首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将Meteor用户发布到管理

将Meteor用户发布到管理
EN

Stack Overflow用户
提问于 2013-08-14 04:16:02
回答 1查看 753关注 0票数 3

我试图发布所有的电子邮件和“角色”给“管理员”用户(使用流星角色陨石包),服务器知道它想发布什么,但出于某种原因,客户端没有收集数据。下面是所涉及的代码:

服务器代码:

代码语言:javascript
运行
复制
Meteor.publish("directory", function() {
   if(Roles.userIsInRole(this.userId, 'admin')) {
      //next line shows that it outputs that there are 2 documents in this
      console.log(Meteor.users.find({}, {fields:{emails:1, roles:1}}).count());
      return Meteor.users.find({}, {fields:{emails:1, roles:1}});
   } else {
      return {};
   }
}

客户代码:

代码语言:javascript
运行
复制
Meteor.subscribe("directory");
Directory = new Meteor.Collection("directory");

//and then to simulate my use for this collection
console.log(Directory.find().count());
//which outputs 0

为什么客户没拿到文件?(我肯定是用一个角色“admin”的帐户登录)

谢谢!

编辑和解决方案!

好吧,所以我知道我做错了什么。我只需要在服务器上发布“目录”,并在客户机上订阅。然后,所有用户数据都进入Meteor.users集合,我不应该定义自己的"Directory=new Meteor.Collection(‘目录’)“。然后,我可以通过Meteor.users访问数据。干杯!

服务器:使用与上面相同的代码

客户端:

代码语言:javascript
运行
复制
Meteor.subscribe("directory");
console.log(Meteor.users.find().count()); //outputs 2, yay!
EN

回答 1

Stack Overflow用户

发布于 2013-08-14 07:48:45

您的集合可能应该在开始时定义,以便客户端知道在哪里编写!

另外,在加载应用程序时,您的Meteor.subscribe("directory");只运行一次。你应该做出反应。

代码语言:javascript
运行
复制
Directory = new Meteor.Collection("directory");

Deps.autorun(function(){
  Meteor.subscribe("directory");
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18223106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档