简体   繁体   English

流星和CoffeeScript:无法调用未定义的方法“帮助器”

[英]Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

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. 我刚刚为Meteor设置了CoffeeScript(我也使用了Jade),看来我的助手(也包括渲染和事件功能)不再起作用。

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')

The problem is fixed when I wrap my code with Meteor.startup (see David Weldon post ). 当我用Meteor.startup包装代码时,此问题已解决(请参阅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 . 如果我将.jade和.coffee放在同一级别的文件夹中,则流星会在.jade之前加载.coffee,那么它不会导致此类模板 To prevent this, you can prefix jade files with _. 为了防止这种情况,可以在_玉文件中添加_前缀。

Thanks for the great pointer @Julien. 感谢伟大的指针@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 我做的不是_方法,而是将我的玉文件命名为.html.jade,将我的coffeescript文件命名为.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. 希望这可以帮助。

我认为这是在流星玉v0.2.2中解决的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM