我似乎无法使用以下代码从服务器端获得响应式集合更改:
Template.name.onRendered(function() {
this.autorun(function(){
Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
//update UI
});
});
});
当Session.get("start")
更改时,它会正确地订阅服务器范围内的所有项目,但如果我从mongo shell中删除项目,则不会调用订阅回调,即重新订阅不是在客户端触发,我需要让这两个条件有效,
我几乎可以使用另一个自动运行来跟踪Items.find()查询,
Template.name.onRendered(function() {
// when user changed the date range, get the new data
this.autorun(function(){
Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
//update UI
});
});
// get all the changes from server and update UI
this.autorun(function(){
Items.find(start, end);
//update UI
});
});
但似乎在每次订阅完成后,查询自动运行也会运行,这不是必需的,它真的应该只从服务器中选择更改,我该怎么做以反映服务器端范围内的任何更改客户端?