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/