使用meteor与咖啡和玉:callback .call不是一个函数
我一直在用Coffeescript和Jade尝试Meteor。 而对于最基本的应用程序,我写了下面的代码。
main.coffee
import './hello.coffee' import './main.jade'
main.jade
head title Chatter body h1 Welcome to Chatter! +hello
hello.coffee
import { Template } from 'meteor/templating' import { ReactiveVar } from 'meteor/reactive-var' import './hello.jade' Template.hello.onCreated helloOnCreated: -> @counter = new ReactiveVar 0 return Template.hello.helpers counter: -> Template.instance().counter.get() Template.hello.events 'click button': (event, instance) -> instance.counter.set instance.counter.get() + 1 return
hello.jade
template(name="hello") button Click me! p You have pressed the button #{counter} times.
现在,当我试图运行这个应用程序,我得到这个错误Uncaught TypeError: callbacks[i].call is not a function
。 我对此很新,所以任何帮助将不胜感激。 谢谢!
你当前正在传递一个helloOnCreated
属性的Template.hello.onCreated
对象。 只需传递Template.hello.onCreated
直接创build一个函数。
Template.hello.onCreated -> @counter = new ReactiveVar 0 return
从Meteor的文档中 , onCreated
, onRendered
和onDestroyed
属性接受函数。
events
和helpers
属性接受对象,就像你有。