【问题标题】:insert meteor.userId into mongoDB将meteor.userId插入mongoDB
【发布时间】:2016-03-03 12:48:16
【问题描述】:

我想在 simpleSchema 中初始化一个字段。我想将 userId 设置为字符串字段。

这是架构:

AdsSchema = new SimpleSchema({
  title: {
    type: String,
    label: "Title"
  },
  insertedBy: {
    type: String,
    label: "Inserted By",
    autoform:{
      type:"hidden"
    },
    autoValue: function() {
      if (this.userId) {
        return this.userId;
      }
    }
  }
}

但是通过autoform插入后,插入的文档是:

{
    "_id" : "Zm5TML5bwJhyN8B9F",
    "title" : "test"
}

表示“insertedBy”字段的值为“null”!

我该如何解决这个问题?

【问题讨论】:

    标签: mongodb meteor-accounts meteor-autoform meteor-collection2 simple-schema


    【解决方案1】:

    试试if(Meteor.userId()) return Meteor.userId()

    autoValue 中的this 的属性有限,请查看文档Autoform Docs

    对 autoValue 进行了一些研究,在cleaning Data 下提到了属性extendAutoValueContext,这有助于使用 userId .

    【讨论】:

    • 我使用 Meteor.userId() 而不是 this.userId ,问题解决了。谢谢
    猜你喜欢
    • 2014-08-10
    • 1970-01-01
    • 2014-03-02
    • 2013-02-22
    • 2013-03-06
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多