【发布时间】:2016-09-20 12:14:10
【问题描述】:
在我的带有 Flow 路由器的流星应用程序中,我使用流星订阅来获取用户数据,但助手中的数据没有根据用户集合更新进行更新。
在我的发布代码中,
Meteor.publish('fetchUserData', function(usrnm) {
return Meteor.users.find({'username':usrnm}, {
fields: {
profile: true,
services: true,
emails: true,
votedPatents: true,
userType: true,
followingUsers: true,
followedByUsers: true
}
});
});
在我的 router.js 文件中,
Subs = new SubsManager();
FlowRouter.route('/:username', {
subscriptions: function(params) {
this.register('fetchUserData', Meteor.subscribe('fetchUserData', params.username));
},
action: function(params) {
BlazeLayout.render('main', {center: 'profile'});
})
}
});
在我的客户端代码中
Template.profile.onCreated(function() {
this.autorun(function() {
var handle = Subs.subscribe('fetchUserData', username);
})
})
Template.profile.helpers({
connections: function(){
var u = Meteor.users.findOne({'username':username});
return u;
}
})
还应注意,辅助函数为 Meteor.user() 以外的用户返回 undefined ,我也尝试过 How to access FlowRouter subscriptions in Meteor template helpers? ,但结果相同
【问题讨论】:
标签: meteor meteor-blaze flow-router