我刚刚为 Meteor 设置了 CoffeeScript(我也在使用 Jade),看来我的助手(渲染和事件函数)不再工作了。
Template.signIn.helpers
showForgotPassword: () ->
return Session.get('showForgotPassword')
该代码似乎已正确生成,但包含在匿名函数中。
我在 Web 控制台中收到以下错误:
Uncaught TypeError: Cannot call method 'helpers' of undefined (account.coffee:12)
我想知道代码是否在页面完全加载之前运行,或者是否由于其他原因而运行。我也尝试过这个,但没有任何改变(尽管它似乎在这个 tutorial 中工作):
root = global ? window
root.Template.signIn.helpers
showForgotPassword: () ->
return Session.get('showForgotPassword')
最佳答案
当我用 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文件中添加_前缀。
关于javascript - Meteor 和 CoffeeScript : Cannot call method 'helpers' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21352498/