【问题标题】:How to use data from meteor subscription如何使用来自流星订阅的数据
【发布时间】:2017-02-22 21:05:03
【问题描述】:

我在 Meteor 应用程序的用户集合的根目录中添加了额外的字段,并且无法从反应中访问它们。 这是出版物:

if (Meteor.isServer) {
   // This code only runs on the server

 Meteor.publish('currentUserInfo', () => {
     if (!this.userId) {
         return this.ready();
     }

     return Meteor.users.findOne({_id: this.userId});
 }); }

这里是订阅:

export default createContainer(()=>{
    Meteor.subscribe('currentUserInfo');

    return {
        currentUser: ???,

如何通过 props 传递订阅数据?

【问题讨论】:

    标签: reactjs meteor subscription


    【解决方案1】:

    Meteor.user()

    Meteor.users.findOne(Meteor.userId())

    【讨论】:

    • 不工作。它只返回预定义的属性,例如用户名和电子邮件。
    • Meteor.users.findOne( Meteor.userId() ) Object { _id: "Lm5LiXAt4pPFszHhC", emails: Array[1] }
    • 你说得对,但问题是发布代码很累,由于某种奇怪的原因没有在服务器上执行
    • 很高兴你知道了 :)
    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    相关资源
    最近更新 更多