[英]Subscribe to Meteor.users() both listing all users and this.userId
页面客户:列出用户集合中的所有用户。 页面配置文件:仅列出已登录的用户配置文件信息。
if (Meteor.isServer) {
Meteor.publish("userData", function () {
return Meteor.users.find({}, {
fields: {
// VISIBLE
'profile.mobile': 1,
'profile.zipcode': 1,
'profile.first_name': 1,
'profile.work_title': 1,
'emails[0].address': 1,
}});
});
}
Template.profileDetails.helpers({
user: function() {
return Meteor.users.find({_id: this.userId});
},
userEmail: function() {
return this.emails[0].address;
},
userFirstName: function() {
return this.profile.first_name;
},
userTitle: function() {
return this.profile.work_title;
},
userMobile: function() {
return this.profile.mobile;
},
userZip: function() {
return this.profile.zipcode;
},
});
Template.customerDetails.helpers({
user: function() {
return Meteor.users.find();
},
userEmail: function() {
return this.emails[0].address;
},
userFirstName: function() {
return this.profile.first_name;
},
userTitle: function() {
return this.profile.work_title;
},
userMobile: function() {
return this.profile.mobile;
},
userZip: function() {
return this.profile.zipcode;
},
});
个人资料页面根本没有显示任何信息。 我如何才能只显示已登录的用户信息? 谢谢!
助手中的“ this”不是用户。 由于您要在个人资料模板中查找当前用户,因此无需帮助者即可在Blaze中进行操作:
{{currentUser.profile.first_name}}
对于客户,您可以遍历助手返回的用户。 我将重命名该助手:
Template.customerDetails.helpers({
customers(){
return Meteor.users.find({});
}
});
然后您可以像这样在Blaze中循环播放它们:
{{#each customer in customers}}
{{customer.profile.first_name}}
{{else}}
No customers found.
{{/each}}
请注意,您不需要任何其他帮助者即可完成该工作。
要获取当前登录的用户,可以使用: Meteor.user()
:
//...
user: function() {
return Meteor.user();
},
//...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.