简体   繁体   中英

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.

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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