【发布时间】:2014-06-16 18:54:30
【问题描述】:
所以,在我的 server.js 中,我有以下代码来限制客户端接收的内容:
Meteor.publish('customerList', function()
{
return Meteor.users.find({roles: 'customer'}, {fields: {profile: 1}});
});
我只想使用 Roles 包查找具有价值 'customer' 的 'roles' 的用户。然后在 client.js 我做另一个 find() 订阅:
Meteor.subscribe('customerList', function()
{
var foundCustomers = Meteor.users.find().fetch();
Session.set('foundCustomers', foundCustomers); //i have a Session.get elsewhere which returns this cursor
});
当然,在我的模板中,我会像这样显示这些值:
<template name="customer_search_result">
{{#each customers}}
<div>{{profile.firstname}} {{profile.lastname}}, {{profile.tel}}</div>
{{/each}}
</template>
那么当我现在看到此列表中的所有不同角色时,我做错了什么?如果我在订阅的find() 中添加与我发布的相同的规则,那么我们根本不会得到任何结果。
【问题讨论】:
-
您已删除自动发布包?
-
是的,没错,我删除了 autopublish 包,因为这是 Roles 抱怨的东西^^
-
该发布是唯一发布来自
Meteor.users集合的文档的发布? -
roles字段包含您要排除的用户的什么内容?是否只是例如['admin']还是['admin', 'customer']之类的? (您可以通过在命令行输入meteor mongo然后执行db.users.find()来检查) -
No Peppe,还有另一个发布“员工”类型的用户。我想同时发布一个employeeList 和一个customerList。 user3374348,角色只包含一个字符串,如“admin”或“customer”atm。
标签: javascript meteor