繁体   English   中英

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

[英]Meteor simple-schema array should have defaultValue none

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

createEvent.jade

template(name="createEvent")
  +quickForm(collection="Events" id="createEventForm" type="insert" fields="name,description,location")

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

  crew: {
    type: [String],
    label: "Crew",
    defaultValue: ""
  },

autoValue将创建者添加为成员:

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

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

  host: {
    type: String,
    label: "Host",
    autoValue: function() {
      return this.userId;
    },
  },

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

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

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

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

crew: {
    type: [String],
    label: "Crew",
    defaultValue: [],
    minCount: 0
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM