我一直在尝试使用 Coffeescript 和 Jade 来使用 Meteor。对于最基本的应用程序,我编写了以下代码。
主.咖啡
import './hello.coffee'
import './main.jade'
main.jade
head
title Chatter
body
h1 Welcome to Chatter!
+hello
你好咖啡
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
你好 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
属性接受对象,就像您一样。
关于node.js - 将 meteor 与 CoffeeScript 和 Jade 一起使用 : callback[i]. 调用不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46370062/