mongodb - Meteor - 将所有用户发布到客户端,仅供管理员使用

标签 mongodb templates meteor

Meteor 有以下问题: 我有一个管理员,需要查看所有注册用户。 但是所有其他用户不应该有看到其他用户的能力。 因此,我在服务器端发布了以下代码

Meteor.publish("adminUsers", function(){

   var result; 
   if (Roles.userIsInRole(this.userId, ["admin"]))
   {
        result = Meteor.users.find();
   }
   //console.log(result);
   return result;
});

在客户端我订阅了这个

Meteor.subscribe("adminUsers");

然后做

AllUsers = new Meteor.Collection("adminUsers");

现在我想使用以下代码获取模板中的所有用户:

Template.adminUserverwaltung.AllUsers = function(){
console.log(AllUsers.find());
return AllUsers.find();
}

并使用以下代码在模板中显示结果:

    <template name="adminUserverwaltung">
  {{#each AllUsers}}
    {{this.username}}
  {{/each}}
</template>

但不幸的是,它不起作用...有人可以帮我吗?

最佳答案

当您订阅该集合时,订阅名称是 adminUsers,但用户集合仍然是 Meteor.users,它已被定义。

所以只需更改它以使用它来代替

Template.adminUserverwaltung.AllUsers = function(){
    return Meteor.users.find();
}

关于mongodb - Meteor - 将所有用户发布到客户端,仅供管理员使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660171/

相关文章:

node.js - 在不重新启动 "server"的情况下编码 node.js

node.js - 如何使用使用角度2发布的nodejs保存包含图像的表单数据

c# - MongoDB 数组查询

mongodb - Docker mongo auth SCRAM-SHA-1

html - 展望负表 margin

c++ - 从元组派生类

node.js - Node.js 上 MongoDB 连接的最佳实践是什么?

带有变量的 PHP 模板类?

javascript - Meteor 插入方法回调应该执行异步

meteor - 为什么 meteor 0.6.0 将所有内容都包装到 (function(){ ... })