[英]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.