node.js - 将 meteor 与 CoffeeScript 和 Jade 一起使用 : callback[i]. 调用不是函数

标签 node.js meteor coffeescript pug

我一直在尝试使用 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 documentationonCreatedonRenderedonDestroyed 属性接受函数。

eventshelpers 属性接受对象,就像您一样。

关于node.js - 将 meteor 与 CoffeeScript 和 Jade 一起使用 : callback[i]. 调用不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46370062/

相关文章:

node.js - 无法在 OS X El Capitan 上启动 Node.js

node.js - 我需要使用 nginx 服务器为 node.js 项目设置我的域

node.js - 如何下载 MUP 发送的 Meteor 应用程序?

windows - 为什么我会收到 ENOTEMPTY 错误?

javascript - Rails 4 - CoffeeScript 无法正常工作

javascript - 自定义运行时 node.js - 在 Google App Engine 中看不到我的自定义日志

javascript - 为什么使用 sails-auth 验证后/user/me Controller 中 "req.user"始终为空?

通过 3rd 方邮件发送 meteor 验证、注册等电子邮件

javascript - Rest In Place gem 成功事件回调

javascript - 如何使用coffeescript在rails中请求 "PUT"