[英]Meteor Update Collection After Login
I'm two weeks newbie for Meteor. 我是流星的两个星期新手。 I have some issue - I found my collection didn't update after I login. 我遇到了一些问题-登录后我的收藏集没有更新。
Meteor.subscribe("special",Meteor.userId());
Meteor.userId() suppose to be null and I can't get correct data. Meteor.userId()应该为null,我无法获取正确的数据。 I'd also found this collection hadn't update after user login. 我还发现该集合在用户登录后没有更新。
So I add bellow code - 所以我添加下面的代码-
if(Meteor.isClient) {
Meteor.subscribe("special",Meteor.userId());
/* update */
Accounts.onLogin(
function() {
Meteor.subscribe("special",Meteor.userId());
}
);
} }
I'm not sure about the policy of meteor. 我不确定流星的政策。 Did I break anything for this kind of code? 我为这种代码破坏了任何东西吗?
thanks 谢谢
Try this: 尝试这个:
Tracker.autorun(function(){
Meteor.subscribe("special",Meteor.userId());
});
And in server side 在服务器端
Meteor.publish("special", function() {
if (this.userId) {
// ... return Special.find() for instance
} else {
return [];
}
});
Hope this help! 希望对您有所帮助!
Here's a variation on the pattern - we subscribe to the collection and ask it to call us back after it loads 这是模式的一种变化-我们订阅了该集合,并要求它在加载后给我们回电
Tracker.autorun(function(){
if ( Meteor.user() ){
var sub = Meteor.subscribe('collection',function(){
var object = collection.findOne(); // we won't get here until the collection is ready on the client
... do stuff ...
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.