【问题标题】:using meteor with coffeescript and jade: callback[i].call is not a function将流星与咖啡脚本和玉一起使用:回调[i].call 不是函数
【发布时间】:2018-03-04 08:22:04
【问题描述】:

我一直在用 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。我对此很陌生,因此将不胜感激任何帮助。谢谢!

【问题讨论】:

    标签: node.js meteor coffeescript pug


    【解决方案1】:

    您当前正在传递 Template.hello.onCreated 一个具有 helloOnCreated 属性的对象。直接传Template.hello.onCreated一个函数就好了。

    Template.hello.onCreated ->
        @counter = new ReactiveVar 0
        return
    

    Meteor's documentationonCreatedonRenderedonDestroyed 属性接受函数。

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

    【讨论】:

    • 不是没有!如果您是第一次尝试 Meteor,我建议您使用 Meteor 的内置 Blaze 模板引擎和标准 Javascript。我知道您可以使用 Jade 和 Coffeescript,但是从 Meteor 的标准开始,您可能会更好地了解 Meteor 的机制(并且可以更多地访问示例代码)。只是一个建议。闲暇时无视。 :)
    • 是的,我已经按照 Blaze 的官方 todos 教程进行操作。我正在自己制作一个应用程序,所以我想尝试一下 CoffeeScript。感谢您的建议和帮助。 :)
    猜你喜欢
    • 2016-01-05
    • 1970-01-01
    • 2016-02-26
    • 2011-11-08
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    相关资源
    最近更新 更多