Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

自闭症网瘾萝莉.ら 提交于 2019-12-24 17:37:08

问题


I just set up CoffeeScript (I'm also using Jade) for Meteor and it seems that my helpers (rendered and events functions too) do not work anymore.

Template.signIn.helpers
    showForgotPassword: () ->
        return Session.get('showForgotPassword')

The code seems to be properly generated but is embraced in an anonymous function.

I'm getting the following error in the web console:

Uncaught TypeError: Cannot call method 'helpers' of undefined (account.coffee:12)

I'm wondering whether the code is run before the page is fully loaded or if it is due to something else. I've also tried this but nothing changed (though it seems to work in this tutorial):

root = global ? window

root.Template.signIn.helpers
    showForgotPassword: () ->
        return Session.get('showForgotPassword')

回答1:


The problem is fixed when I wrap my code with Meteor.startup (see David Weldon post).

if I put .jade and .coffee into same level folder meteor will load .coffee before .jade, then it causes no such template. To prevent this, you can prefix jade files with _.




回答2:


Thanks for the great pointer @Julien.

I run into this issue about a few hours back and have been breaking my head since.

What I did instead of the _ approach, was to name my jade files as .html.jade and my coffeescript files as .js.coffee

That way the jade files are loaded before the coffee files and everything works.

The advantage to the _ approach is that related jade and coffee files are together.

Hope this helps.




回答3:


I think this is solved in meteor-jade v0.2.2



来源:https://stackoverflow.com/questions/21352498/meteor-and-coffeescript-cannot-call-method-helpers-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!