简体   繁体   English

列出流星中的所有用户电子邮件

[英]List all users email in meteor

I want to list All registerd users email and CompanyName, I have 3 registered users, but in my case it shows only current user email and company name: 我想列出所有注册用户的电子邮件和公司名称,我有3个注册用户,但在我的情况下,它仅显示当前用户的电子邮件和公司名称:

在此处输入图片说明 在此处输入图片说明 This is .js file, in clien: 这是.js文件,以clien开头:

Template.homepage.helpers({
    user: function(){
        return Meteor.users.find();
    }
});

Template.homepage.helpers({
    userEmail: function(){
        return this.emails[0].address;
    }
});

And this is html file: 这是html文件:

<div class="row text-center">
        {{ #each user }}
        <div class="col-sm-4">
            <div class="thumbnail">
                <img src="..." alt="">
                <p><strong>{{userEmail}}</strong></p>
                <p>{{profile.companyName}}</p>
            </div>
        </div>
        {{/each }}
    </div>

Why it does not show other users email and CompanyName? 为什么不显示其他用户的电子邮件和公司名称? Where is my mistake, can you help me with this issue? 我的错误在哪里,您可以帮我解决这个问题吗? Thank you in advance! 先感谢您!

As I can see, you can check two things. 如我所见,您可以检查两件事。

First is if all users have the same data on its documents. 首先是所有用户在其文档上是否具有相同的数据。 On your printscreen, only first user have an email. 在打印屏幕上,只有第一个用户有一封电子邮件。 Second one dont even have a profile item, and third one dont have an email. 第二个人甚至没有个人资料,第三个人没有电子邮件。

If it is OK and all users have all fields on database, then probably you should Publish that data from server and Subscribe to that content. 如果可以,并且所有用户在数据库中都有所有字段,那么您可能应该从服务器Publish该数据并Subscribe该内容。 By default (if insecure and autopublish packages are already removed), Meteor publishes only your own user data, and not others data. 默认情况下(如果已经删除了insecureautopublish程序包), Meteor仅发布您自己的用户数据,而不发布其他数据。

So you would need to add on server something like this: 因此,您需要在server上添加如下内容:

 Meteor.publish("allusers", function () {
      if (!this.userId) {
           // this will make this available just to logged in users, and not for everyone.
           this.ready();
           return;
      }
      return Meteor.users.find({},{
          fields: {
              // here you can hide some of the data to be published. 
              //'0' means that that information will not be published to client.
              // you can also change to '1' instead of '0'. Then instead of hiding some
              // data, you would just show those listed.
              'services': 0,
              'createdAt': 0,
              'username': 0, //as you want emails, so you should hide this one.
              'profile.birthday': 0,
              'profile.activationcode': 0
          }
     });
});

Finally, on client, you should subscribe to that publishing on pages you will need it. 最后,在客户端,您应该在需要的页面上订阅该发布。 I do not know your application and what is will be used for, but it is recommended to hide user data from public access. 我不知道您的应用程序及其用途,但是建议对公共访问隐藏用户数据。 Publishing that content should be done only on safe places. 只能在安全的地方发布该内容。 That is why I have left there that code for publishing only for logged in users. 这就是为什么我只剩下用于登录用户发布的代码的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM