【发布时间】:2013-11-04 15:19:27
【问题描述】:
正如我从文档中了解到的那样,模板是在 Deps 自动运行中呈现的, 并且所有状态更改的停止/订阅都将由它维护,例如如果 abc.elements 是 多次调用。
当模板从屏幕上移除时,订阅也会停止或 我必须在 Template.destroy 方法中手动删除它吗?
[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>
【问题讨论】:
标签: templates meteor subscription