我有这个代码:
Template.temp.rendered = function () {
console.log('temp rendered');
}
仅在网站初始化时记录。
但我做这样的事情:
more = function () {
Meteor.subscribe('Videos', Session.get('more_info'));
}
当我调用 more(); 即使模板 dom 使用新文档更新,它也不会记录“临时渲染”。还尝试了类似的东西:
Template.temp.rerendered = function () {
console.log('temp re rendered');
}
这没用; 我如何知道 A 模板是否被重新渲染?
目前我正在做这样的事情
$('#list').bind("DOMSubtreeModified",function(){
console.log('template modified'}
//this logs like 200 times, every time the template is re rendered
)
我怎样才能以流星的方式做到这一点?
列表模板:
<template name="list">
{{#each list}}
<a id="{{_id}}" href="/{{category}}/{{_id}}" title="{{vTitle}}">
{{vTitle}}
</a>
{{/each}}
</template>
帮手:
Template.list.helpers({
list : function () {
return Videos.find({},{sort : {date : -1}});
}
})
试过(不工作):
Template.list.rendered = function () {
this.autorun(function() {
Videos.find();
console.log('template re rendered');
});
}
首选解决方案(来自@richsilv):
Template.list.rendered = function () {
this.autorun(function() {
Videos.find().count();
console.log('template re rendered');
});
}
如果您每次渲染模板时都需要调用一个函数并且不想注册自动运行,那么@Peppe LG 的解决方案也很好。