Meteor简单模式数组应该没有defaultValue

Kin*_*Guy 3 javascript meteor meteor-autoform meteor-collection2

我有一个表格供人们创建一个事件,以后会有成员,但不是在创建时.创建事件时,不应添加任何成员,因此autoform不显示任何成员字段:

createEvent.jade

template(name="createEvent")
  +quickForm(collection="Events" id="createEventForm" type="insert" fields="name,description,location")
Run Code Online (Sandbox Code Playgroud)

对于要提交的表单,我相信我必须确保Events集合中所有必填字段都有值,即使不是表单.表单将不会提交(提交按钮无效,我正在检查minimongol以确保没有记录条目)即使我已经尝试添加defaultValue:

  crew: {
    type: [String],
    label: "Crew",
    defaultValue: ""
  },
Run Code Online (Sandbox Code Playgroud)

autoValue将创建者添加为成员:

  crew: {
    type: [String],
    label: "Crew",
    autoValue: function() {
      return this.userId;
    },
  },
Run Code Online (Sandbox Code Playgroud)

我在一分钟前遇到这个问题,默认情况下没有表单字段设置事件创建者,现在它可以工作:

  host: {
    type: String,
    label: "Host",
    autoValue: function() {
      return this.userId;
    },
  },
Run Code Online (Sandbox Code Playgroud)

但我不能得到这个基于数组的默认值.我也试过defaultValue: "['']"了一些其他人.坚持到现在,请帮忙..

kao*_*eya 5

如果您希望将创建者添加为默认成员,则可以使用以下命令:

crew: {
    type: [String],
    label: "Crew",
    autoValue: function() {
        if( this.isInsert ) {
            return [ this.userId ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果要在默认情况下插入空数组,请尝试:

crew: {
    type: [String],
    label: "Crew",
    defaultValue: [],
    minCount: 0
}
Run Code Online (Sandbox Code Playgroud)

  • 很多香草JS,[]表示一个空数组. (2认同)