【发布时间】:2014-12-18 00:01:06
【问题描述】:
有人能看出为什么路由没有订阅该出版物吗? Profiles = new Meteor.Collection('profiles');
mongo 数据库在此集合中确实有文档,但浏览器控制台在 Profiles 集合中的计数仍然为 0。
我试图告诉路由器,“订阅用户配置文件发布,当你准备好时,呈现'配置文件'模板。我还将路由命名为'配置文件'。”
现在我注意到在输入sub = Meteor.subscribe('user-profile'); 和sub.ready(); 之后,我得到了集合的计数。否则不订阅路径。这种行为以前没有发生过。
lib/router.js
Router.plugin('loading', {loadingTemplate: 'Loading'});
Router.route('user/profile', {
name: 'profile',
waitOn: function () {
// return one handle, a function, or an array
return Meteor.subscribe('user-profile');
},
action: function () {
// this.ready() is true if all items returned from waitOn are ready
if (this.ready())
this.render('profile');
else
this.render('Loading');
}
});
server.js:
Meteor.publish('user-profile', function () {
return Profiles.find({userId: this.userId});
});
userId 是 Profiles 集合中的一个字段。此配置文件 doc id 存储在 user.profile.experiences 数组中以供参考。
【问题讨论】:
标签: meteor iron-router