将 meteor 与 coffeescript 和 jade 一起使用:callback[i].call 不是函数
using meteor with coffeescript and jade: callback[i].call is not a function
我一直在用 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
。我对此很陌生,因此将不胜感激任何帮助。谢谢!
您目前正在传递 Template.hello.onCreated
一个带有 helloOnCreated
属性 的对象。直接传Template.hello.onCreated
一个函数就可以了。
Template.hello.onCreated ->
@counter = new ReactiveVar 0
return
从 Meteor's documentation 开始,onCreated
、onRendered
和 onDestroyed
属性接受函数。
events
和 helpers
属性接受对象,就像您拥有的一样。
我一直在用 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
。我对此很陌生,因此将不胜感激任何帮助。谢谢!
您目前正在传递 Template.hello.onCreated
一个带有 helloOnCreated
属性 的对象。直接传Template.hello.onCreated
一个函数就可以了。
Template.hello.onCreated ->
@counter = new ReactiveVar 0
return
从 Meteor's documentation 开始,onCreated
、onRendered
和 onDestroyed
属性接受函数。
events
和 helpers
属性接受对象,就像您拥有的一样。