当用户导出模板时,如何停止观察游标(客户端)的更改?
Template.postPage.created = function(){
var postId = Router.current().params._id;
postCursor = Posts.find(postId);
postHandle = postCursor.observeChanges({
changed: function(id, fields){
// actions
}
});
};
我正在使用铁制路由器。
答案 0 :(得分:1)
您可以将变量分配给模板实例,并在其被销毁时停止:
Template.postPage.created = function(){
var postId = Router.current().params._id;
var postCursor = Posts.find(postId);
this.postHandle = postCursor.observeChanges({
changed: function(id, fields){
// actions
}
});
};
Template.postPage.destroyed = function() {
this.postHandle.stop();
}