【问题标题】:Meteor - onRendered is not a functionMeteor - onRendered 不是一个函数
【发布时间】:2015-04-24 15:10:52
【问题描述】:

我有最新版本的 Meteor...

meteor --version
Meteor 1.1.0.2

the documentation 是这么说的……

Template.codeSample.onRendered(function () {
  hljs.highlightBlock(this.findAll('pre'));
});

这是我的 js 代码...

if (Meteor.isClient) {
  Template.virtuebox.onRendered(function () {
    console.log("hi")
  });
}

这是我的模板...

<template name="virtuebox">     
      <div class="box">
        <span>{{text}}</span>
        <input type="number" value="0.5" step="0.1" min="0" max="1" name={{text}} />
      </div>
</template>

这是方法列表...

这是错误...

simple-todos.js:34 Uncaught TypeError: Template.virtuebox.onRendered is not a function

我做错了什么?

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    这很奇怪……我很想知道你的系统是否没有良好的火焰。

    真的,新的

    Template.foo(onRendered(function(){}));
    

    机制很有意义,因为它提供了多个回调而不是旧的

    Template.foo.rendered = function(){};
    

    它只给了你一个 - 但这不会导致你的问题。

    Template.prototype 的某些可见部分(即 onCreated、onRendered、onDestroyed 和 _getCallbacks 函数以及 _callbacks 对象)的缺失让我认为您系统上的 packages/blaze/template.js 已经以某种方式受到了损害。

    您可以尝试查看旧的 Template.foo.rendered 是否有效,尽管 _getCallbacks 函数的代码内文档指出

    // Fire all callbacks added with the new API (Template.onRendered())
    // as well as the old-style callback (e.g. Template.rendered) for
    // backwards-compatibility.
    

    我不认为这会更好;不清楚你的系统上有什么。

    如果做不到这一点,我会尝试从您的系统中删除流星并重新安装它。如果系统上的流星源被破坏了,重新安装应该可以修复它。

    【讨论】:

    • Template.foo.rendered = function(){} 正在工作,感谢您的建议。我正在使用最新版本的流星,所以我会尽量了解这一点。
    猜你喜欢
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2016-03-25
    • 2015-06-22
    • 2016-02-09
    • 1970-01-01
    相关资源
    最近更新 更多