【发布时间】:2016-10-06 08:19:50
【问题描述】:
发布和订阅不起作用。请在下面找到解决方案作为答案。
最初的问题: 我正在尝试发布使用 Meteor 中的帐户 facebook 包登录时自动检索的 facebook first_name(存储在 services.facebook 下的用户集合中)。我已删除自动发布和不安全。
到目前为止我尝试过的看起来是这样的:
服务器端
Meteor.publish("facebook_name", function() {
return Meteor.users.find({_id: this.userId},
{fields: {'services.facebook.first_name' : true} });
});
客户端
Meteor.subscribe('facebook_name');
我在模板中使用的是这个
<div class="Name"><p>{{currentUser.services.facebook.first_name}}</p></div>
在删除自动发布之前,模板中显示的名称。
【问题讨论】:
-
你试过 {fields: {'services.facebook.first_name' : 1} 吗?
-
是的,我试过了,没有改变任何东西
-
您的订阅在哪里?可以出示一下代码吗?
-
这是我现在拥有的第一个订阅。到目前为止它在 client/main.js 中。
标签: javascript facebook meteor publish-subscribe meteor-accounts