我已经为我正在开发的应用程序构建了一个用户个人资料页面,当用户登录时该页面工作正常,但当没有人登录时,模板为空。我的目标是任何人(即使它没有在应用程序中注册)都能够看到用户配置文件。
这是代码:
出版物:
Meteor.publish('singleUser', function(userId) {
if (this.userId) {
var findById = Meteor.users.find(userId);
return findById.count() ? findById : 'undefined';
}
return [];
});
路由器:
this.route('user_profile', {
path: '/users/:_id',
waitOn: function() {
return Meteor.subscribe('singleUser', this.params._id);
},
data: function() {
return Meteor.users.findOne({_id: this.params._id});
}
});
个人资料模板:
<template name="user_profile">
<h4>Username</h4>
<p>{{username}}</p>
<h4>User since:</h4>
<p>{{createdAtFormatted}}</p>
</template>
个人资料助手:
Template.user_profile.helpers({
createdAtFormatted: function(){
return moment(this.createdAt).fromNow();
}
});
我不知道我的代码中缺少什么。
谢谢!