javascript - Meteor 和 CoffeeScript : Cannot call method 'helpers' of undefined

标签 javascript coffeescript meteor

我刚刚为 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/

相关文章:

javascript - 来自第 3 方 API 的回调未在 MeteorJS 中获取当前用户

javascript - 为什么这个非常基本的 JS 下拉菜单不起作用?

javascript - 在 Javascript 中重构

javascript - 启用/禁用 <asp :Panel> and all its control using Javascript

CoffeeScript 2 维数组用法

ios - 这个地理定位计算有多准确?

javascript - 有没有办法根据 Coffeescript 中的父类(super class)值在原型(prototype)上定义对象?

javascript - 当路由不存在时,iron-router 渲染 notFound 模板

node.js - 如何延迟铁路由器路由查找

javascript - 仅在 jQuery Mobile 中抑制某些链接的 AJAX/哈希行为