【问题标题】:Meteor reactivity not working after Blaze updateBlaze 更新后流星反应不起作用
【发布时间】:2014-04-07 20:56:36
【问题描述】:

我有一个包含 cmets 部分的详细信息页面。 在 0.8 升级之前,cmets 反应并反映了 minimongo 中的变化,现在它们仅在更新详细对象时更新 代码如下

detail.html

{{#with brick}}
    {{> brick_item}}
    {{> comment_system bind="url" parentType="brick" context=.}}
{{/with}}

cmets.html

<template name="_comment_system">
    <section class="comments">        
        {{#each comments}}
        [...]
        {{/each}}
    </section>
</template>  

cmets.js

Template._comment_system.created = function(){
    var bindFilter =  _BindSwitcher[Template._comment_system.bind()()]();
    Template._comment_system.subscription = Meteor.subscribe("comments", bindFilter);
};

Template._comment_system.destroyed = function(){
    Template._comment_system.subscription.stop();
};

Template._comment_system.helpers({
    comments : function(){
        var queryOptions = _.extend({sort: {createdAt: -1}}, Template._comment_system.reactive());
        if(Template._comment_system.subscription.ready())
            return Comments.find({}, queryOptions);
    }
});

_BindSwitcher = {
    'url' : function(){
        return window.location.pathname;
    },
    'data' : function(){
        return 'bind1'
    }
}
[...]

收藏与出版与平常无异。 问题是 cmets 没有反应性。如果我在 mongodb 中插入评论,它将不会显示在页面中。如果我在 minimongo 中插入评论,它将不会显示。它们仅在 brick 被修改后出现。 而且,如果我将评论系统从 {{#with brick}} 中取出,则 cmets 将永远不会更新,即使在更改 brick 之后也是如此。 0.8之前反应性没有问题。

谁能指出我遗漏了什么以及我是否以不应该的方式使用了某些功能?

提前致谢。

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    删除

    var queryOptions = _.extend({sort: {createdAt: -1}}, Template._comment_system.reactive());
    

    然后放这个

    var queryOptions = _.extend({sort: {createdAt: -1}});
    

    【讨论】:

    • 我没有检查那部分代码,现在我看到它返回 {reactive: false}。奇怪,我敢肯定它以前工作过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2017-04-18
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2015-09-23
    • 2020-11-16
    相关资源
    最近更新 更多