用户电子邮件未显示在模板[METEOR]中!

时间:2015-04-05 13:43:37

标签: meteor meteor-accounts

我有一个用户索引,想要显示每个用户的信息。用户ID显示正常,但应用不会显示电子邮件。

这是我的模板:

<template name="users">
  <h1>List of all users</h1>
  {{#each users}}
    <div class="list_item">
      <p>ID: {{_id}}</p>
      <p>Email: {{email}}</p>
    </div>
  {{/each}}
</template>

这是我的路线:

Router.route('/users', function () {
  this.render('users');
}, {
  waitOn: function() {
    return [
      Meteor.subscribe('users')
    ]
  },

  data:  {users: Meteor.users.find({})}
});

最后,我的出版物:

Meteor.publish('users', function () {
  return Meteor.users.find({}, {fields: {emails: 1, profile: 1}});
});

有什么想法吗?

2 个答案:

答案 0 :(得分:5)

显示电子邮件的正确方法是:

<p>Email: {{emails.[0].address}}</p>

电子邮件地址作为数组存储在用户对象中。

您可以在控制台中输入Meteor.user()进行检查:

Object {
  ...
  emails: Array[1]
    0: Object{
      address: "username@domain.com",
      verified: false
    }
  ...
}

答案 1 :(得分:0)

{{ currentUser.emails.[0].address }}
相关问题