【发布时间】: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