订阅另一个时订阅没有准备好
subscription does not ready while subscribe to another
例如
Router.route('/:username/posts', {
waitOn: function() {
//Meteor.subscribe(('user', this.params.username)); // A
var user = Meteor.users.findOne({username: this.params.username}); // B
if(user) {
return Meteor.subscribe('posts', user._id);
}
}
});
如果我直接在Chrome的地址栏输入http://localhost/userA/posts
回车,代码到B的时候,那个时候Meteor.users还没准备好
如何处理?
用户是否签入发布处理程序。
像这样:
Meteor.publish("posts", function (username) {
var user = Meteor.users.findOne({username: username});
if (user) {
return Posts.find({user: user._id});
}
});
例如
Router.route('/:username/posts', {
waitOn: function() {
//Meteor.subscribe(('user', this.params.username)); // A
var user = Meteor.users.findOne({username: this.params.username}); // B
if(user) {
return Meteor.subscribe('posts', user._id);
}
}
});
如果我直接在Chrome的地址栏输入http://localhost/userA/posts
回车,代码到B的时候,那个时候Meteor.users还没准备好
如何处理?
用户是否签入发布处理程序。
像这样:
Meteor.publish("posts", function (username) {
var user = Meteor.users.findOne({username: username});
if (user) {
return Posts.find({user: user._id});
}
});