Meteor和CoffeeScript:无法调用未定义的方法“helpers” [英] Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

查看:219
本文介绍了Meteor和CoffeeScript:无法调用未定义的方法“helpers”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚设置CoffeeScript(我也使用Jade)的Meteor,似乎我的助手(呈现和事件功能)不再工作。

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.

我在Web控制台中收到以下错误:

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

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

我想知道代码是在页面完全加载之前运行还是由于其他原因。我也试过这个,但没有改变(虽然它似乎工作在这 tutorial ):

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


推荐答案

p>当我用Meteor.startup封装我的代码时,问题已解决(请参阅 David Weldon帖子 )。

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

如果我把.jade和.coffee放到同一级文件夹中meteor会在.jade之前加载.coffee,那么它不会导致这样的模板。为了防止这种情况,你可以用_来为jade文件加上前缀。

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 _.

这篇关于Meteor和CoffeeScript:无法调用未定义的方法“helpers”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆