Templates 模板是否销毁和订阅.stop()?
我从文档中了解到,模板是在Deps自动运行中呈现的, 所有状态更改的停止/订阅将由it维护,例如,如果abc.elements为 打了好几次电话 当模板从屏幕上删除时,订阅也将停止或停止 是否必须在Template.destroy方法中手动删除它Templates 模板是否销毁和订阅.stop()?,templates,meteor,subscription,Templates,Meteor,Subscription,我从文档中了解到,模板是在Deps自动运行中呈现的, 所有状态更改的停止/订阅将由it维护,例如,如果abc.elements为 打了好几次电话 当模板从屏幕上删除时,订阅也将停止或停止 是否必须在Template.destroy方法中手动删除它 [server.js] Elements = new Meteor.Collection('Elements); Meteor.publish('allElements', function() { this.onStop( function()
[server.js]
Elements = new Meteor.Collection('Elements);
Meteor.publish('allElements', function() {
this.onStop( function() {
console.log('allElements.stop');
});
return Elements.find({});
});
[client.js]
Elements = new Meteor.Collection('Elements);
Template.abc.elements = function() {
Meteor.subscribe('allElements);
return Elements.find({});
}
[html]
<template name='abc'>
{{#each elements}}
...
{{/each}}
</template>
[server.js]
元素=新流星集合('Elements');
Meteor.publish('allegements',function()){
this.onStop(函数(){
console.log('allegments.stop');
});
返回元素。查找({});
});
[client.js]
元素=新流星集合('Elements');
Template.abc.elements=函数(){
流星;等位基因;
返回元素。查找({});
}
[html]
{{{#每个元素}}
...
{{/每个}}
当您更改/移动模板时,订阅仍将保留。不完全有必要摆脱它们。如果你回到页面,内容准备得更快
如果你想阻止它们,你可以将它们放入destroy
方法中。如果您正在使用某种路由器,那么最好将其放入其中一个挂钩中,以便在访问页面之前准备就绪
不必取消订阅,除非您在发布中使用了本地化查询,该查询采用参数。e、 g
Meteor.publish("data", function(page) {
return Data.find({page:page});
});
在上述情况下,您需要重新订阅每个页面的内容。但我怀疑你没有这么做