【问题标题】:How to associate post field with user email? [METEOR]如何将帖子字段与用户电子邮件相关联? [流星]
【发布时间】:2015-04-04 01:33:49
【问题描述】:

我已经发布了一个帖子模型,并且运行良好。但是,我通过 simpleSchemas 插件添加了以下字段:

userEmail: {
  type: String,
  autoValue: function() {
    if (this.isInsert) {
      return Meteor.user().email;
    } else if (this.isUpsert) {
      return {$setOnInsert: Meteor.user().email};
    } else {
      this.unset();
    }
  }
}

启用此功能后,提交表单不起作用,但不会引发任何错误。我可能不正确地调用Meteor.user().email 吗?如何将 userEmail 字段与创建帖子的用户的电子邮件相关联?

【问题讨论】:

    标签: meteor meteor-accounts meteor-autoform


    【解决方案1】:

    正确的语法是。

    Meteor.user().emails[0].address
    

    【讨论】:

      【解决方案2】:

      默认 Meteor.users 集合将电子邮件存储在一个数组中(以支持多个电子邮件)。 return Meteor.user().emails[0].address 之类的东西应该可以工作。

      【讨论】:

      • 嗨@Curtis 正确的语法是Meteor.user().emails[0].address 而不是Meteor.user().email[0] 你缺少emails.address
      猜你喜欢
      • 2011-03-24
      • 2016-04-14
      • 2021-12-23
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 2012-10-04
      相关资源
      最近更新 更多