Meteor Collection在升级到0.5.9后不会发送
由于某些原因,在升级到0.5.9之后,我遇到了一个问题,服务器端似乎正确地发送了所有内容,但是客户端说它没有收到任何内容 //服务器:Meteor Collection在升级到0.5.9后不会发送,meteor,Meteor,由于某些原因,在升级到0.5.9之后,我遇到了一个问题,服务器端似乎正确地发送了所有内容,但是客户端说它没有收到任何内容 //服务器: Meteor.publish("orders", function (ordersQueryParams) { console.log("orders publish: " + JSON.stringify(ordersQueryParams)); if (this.userId && ordersQueryParams){
Meteor.publish("orders", function (ordersQueryParams) {
console.log("orders publish: " + JSON.stringify(ordersQueryParams));
if (this.userId && ordersQueryParams){
console.log("orders collection: " + Orders.find({"customer._id": this.userId}, ordersQueryParams).count());
return Orders.find({"customer._id": this.userId}, ordersQueryParams);
}
});
//客户:
var ordersPreferences = {
table: {
size: 10
},
query: {
sort: {createdDate:-1},
skip : 0,
limit : 10
}
};
Session.set("ordersPreferences", ordersPreferences);
Meteor.autorun(function(){
var ordersPreferences = Session.get("ordersPreferences");
console.log('subscribing to orders');
Meteor.subscribe("orders", ordersPreferences.query);
}
//两者:
Orders = new Meteor.Collection("orders");
Deps.autorun(function(){
if (Meteor.isServer)
console.log("on server orders count is " + Orders.find().count());
if (Meteor.isClient)
console.log("on client orders count is " + Orders.find().count());
});
服务器日志:
on server orders count is 26
orders publish: {"sort":{"createdDate":-1},"skip":0,"limit":10}
orders collection: 26
客户端日志:
subscribing to orders
on client orders count is 0
为什么服务器说有26个文档,而客户端坚持0
我快发疯了:(我发现了问题:
我在“等待”我的Meteor.user()
变得可用,并让这个自动运行
:
Meteor.autorun(function(handle){
var ordersPage = new OrdersPage();
if (Meteor.user()) {
ordersPage.init();
ordersPage.autorun();
handle.stop();
}
});
if (Meteor.user()) {
return "orders";
}
一旦找到Meteor.user()
,这个函数就不需要运行,因此我有了handle.stop()
。
显然,从0.5.9开始,handle.stop()不仅停止立即的自动运行
,还停止下面的所有操作(包括集合)
可能是Meteor中引入的一个bug…或者可能是一个新功能。这在0.5.8上运行吗?@Prashant它在0.5.7上运行我注意到Meteor.autorun()已从文档中删除,这可能是问题吗?@Kristoferk根据
Meteor.autorun
和Deps.autorun
这两个功能都应该工作(至少现在是这样)@阿列克谢鲁什科:好的,谢谢。