Meteor 在文档更改时重新呈现 View 。
Template.story.data = function() {
var storyID = Session.get('storyID');
var story = Stories.findOne({
_id: storyID
})
if (!story)
return;
return story;
};
这是故事模板的模板助手,从故事文档中获取故事。
当 story.title
等字段更改时,我希望模板重新呈现。但是当像 story.viewingusers
这样的字段发生变化时,我不想重新呈现模板。无论如何要做到这一点?
触发问题的具体问题已通过将发布功能设置为不发布这些字段来解决。然而,该解决方案并不适用于所有用例,需要一个通用解决方案。
最佳答案
您正在寻找的是 #constant
模板助手。
在你的情况下,我会做的是将弹出框标记包装在一个常量 block 中,然后在 story.rendered
函数中手动更新该 block 中的内容。
所以像这样:
故事.html:
<template name="story">
...
{{#constant}}
<!-- Popover markup here -->
{{/constant}}
...
</template>
客户端.js:
Template.story.rendered = function(){
//Update logic here
}
关于javascript - Meteor 在某些字段更改时不重新呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13371364/