我尝试使用反应性var过滤发布的数据,在数据列表页面上,用户可以选择2个日期以显示在该日期期间创建的数据;一切正常,直到我没有几台计算机可以同时访问该页面;数据更改不会自动推送到每台计算机,只有进行更改的计算机才会列出新数据。其他计算机必须手动刷新页面才能查看新数据或更新的数据。
如果我删除了sub / pub中的反应式变量,那么一切都很好-如果一台计算机更改数据,则所有计算机都会立即自动获取新数据。 我什至将日期过滤器放到帮助程序上-仍然相同-没有DDP推送,与sub / pub中相同。 有任何想法吗?任何输入都非常感谢。v
sub
Template.TestRV.onCreated(function () {
this.startDate = new ReactiveVar({});
this.endDate =new ReactiveVar({});
var sDate = new Date(new Date().setDate(new Date().getDate() - 30));
var eDate = new Date();
//show last 30 days data by default
this.startDate.set(sDate);
this.endDate.set(eDate);
this.autorun(() => {
this.subscribe('shipAllRV',this.startDate.get(),this.endDate.get());
});
//this.autorun(() => {
//this.subscribe('shipAll');
//});
});
Template.TestRV.helpers({
testListRV: function () {
let start = Template.instance().startDate.get();
let end = Template.instance().endDate.get();
return SHIP.find(
{createdAt: { $lte: end,$gte: start }},{ sort: { createdAt: -1 } }
);
},testList: function(){
return SHIP.find({},{ sort: { createdAt:-1} });
}
});
pub -SHIP是我的收藏集
Meteor.publish('shipAll',function() {
return SHIP.find({});
});
Meteor.publish('shipAllRV',function(startDate,endDate) {
return SHIP.find({createdAt:{$lte:endDate,$gte:startDate}},{ sort: { createdAt: -1 } });
});
顺便说一句, 1.我试过的会话变量是相同的; 2.如果我不更新我的SHIP.update方法中的createdAt字段,即使sub / pub中的反应性vars看起来也很好
我该怎么做呢?我需要日期过滤器和DDP推送。谢谢
罗宾