javascript - Displaying other user's email address in Meteor.js - Stack Overflow

Trying to display a view that shows all registered users of the app along with their email addresses. I

Trying to display a view that shows all registered users of the app along with their email addresses. I'm using this pub/sub to pass all user data to the client instead of just the current users data.

Meteor.publish("allUsers", function () {
  return Meteor.users.find();
  });

 Meteor.subscribe('allUsers'); 

Here is the for each loop in my template that is supposed to display their emails:

<template name="daysOverview">
<div class="container-fluid">
<div class="row"> 
{{#each users}}
<h2>Email: {{users.emails.[0].address}}</h2>
{{/each}}

Here is the javascript that is supposed to loop over all of the current registered users and feed their data to the helper.

Template.daysOverview.helpers({
users: function(){
var user = Meteor.users.find(); 
return user; 
},
});

The helper correctly loops over the number of current users of the application (eg. if there are 3 users currently registered it will display 3 instances of "Email: " on the template).

The problem is that I can't find a way to access the email address of each user and display that next to the corresponding "Email: ". I tested accessing a simpler field like "_id" unsuccessfully as well.

I've also tried numerous different binations of {{users.address}}, {{users[0].address}} to access the email with no luck.

Trying to display a view that shows all registered users of the app along with their email addresses. I'm using this pub/sub to pass all user data to the client instead of just the current users data.

Meteor.publish("allUsers", function () {
  return Meteor.users.find();
  });

 Meteor.subscribe('allUsers'); 

Here is the for each loop in my template that is supposed to display their emails:

<template name="daysOverview">
<div class="container-fluid">
<div class="row"> 
{{#each users}}
<h2>Email: {{users.emails.[0].address}}</h2>
{{/each}}

Here is the javascript that is supposed to loop over all of the current registered users and feed their data to the helper.

Template.daysOverview.helpers({
users: function(){
var user = Meteor.users.find(); 
return user; 
},
});

The helper correctly loops over the number of current users of the application (eg. if there are 3 users currently registered it will display 3 instances of "Email: " on the template).

The problem is that I can't find a way to access the email address of each user and display that next to the corresponding "Email: ". I tested accessing a simpler field like "_id" unsuccessfully as well.

I've also tried numerous different binations of {{users.address}}, {{users[0].address}} to access the email with no luck.

Share Improve this question asked Jul 15, 2014 at 23:39 Alex NetschAlex Netsch 1631 silver badge9 bronze badges 4
  • 1 Update: Figured out the answer; im a noob. <template name="daysOverview"> <div class="container-fluid"> <div class="row"> {{#each users}} <h2>Email: {{emails.[0].address}}</h2> {{/each}} Don't call the {{users}} once you're inside your #each statement. – Alex Netsch Commented Jul 16, 2014 at 0:46
  • Make sure to use fields option when you publish users so you don't send things like the services field which contains things like the login tokens and the encrypted password. – David Weldon Commented Jul 16, 2014 at 18:18
  • @AlexNetsch, why not officially answer your own question since you figured it out? – Isaac Gregson Commented Nov 14, 2014 at 15:48
  • Made me wait a few days before "answering my own question" and I forgot @IsaacGregson – Alex Netsch Commented Dec 15, 2014 at 21:32
Add a ment  | 

1 Answer 1

Reset to default 8
{{#each users}}
    <h2>Email: {{emails.[0].address}}</h2>
{{/each}}

Don't call users once you're inside your {{#each users}} block .

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401709a4626134.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信