【问题标题】:Meteor multiple-select autoform流星多选自动生成
【发布时间】:2018-03-21 13:41:15
【问题描述】:

我是流星新手,我对来自 aldeed/meteor-autoform 的流星自动生成有疑问

我想实现一个多选框。

Exercises = new Mongo.Collection('exercises');
ExerciseSchema = new SimpleSchema({
name: {
    label: "Name",
    type: String
},
tags: {
    label: "Tags",
    type: Tags
}});

Tags = new SimpleSchema({
wow: {
    type: String,
    allowedValues: ['red', 'green', 'blue'],
    autoform: {
        options: [
            {label: "Red", value: "red"},
            {label: "Green", value: "green"},
            {label: "Blue", value: "blue"}
        ]
    }
}});

然后在我的 html 中插入

{{#autoForm collection="Exercises" id="insertExerciseForm" type="insert" resetOnSuccess=true}}
            <div class="card-content">
                {{> afQuickField name='tags.wow' type='select-multiple'}}
            </div>

在浏览器中看起来是正确的 Multiple select box select

但是当我选择多个元素并从我的 Autoform 中单击提交按钮时,我在浏览器控制台中收到此错误:

Error in insertExerciseForm insert Error: Wow must be of type String

当我从 afQuickField 中删除 type='select-multiple' 时,我只能选择一个元素并且它工作正常。但我需要选择多个元素

有人可以帮我吗?

【问题讨论】:

    标签: mongodb meteor meteor-autoform simple-schema


    【解决方案1】:

    我认为 type: [String] 而不是 type: String 可以完成这项工作,根据文档:https://github.com/aldeed/meteor-simple-schema

    【讨论】:

      【解决方案2】:

      [String] 没有帮助。

      我发现了。

      Tags = new SimpleSchema({
      wow: {
      type: Array,
      allowedValues: ['red', 'green', 'blue'],
      autoform: {
          options: [
              {label: "Red", value: "red"},
              {label: "Green", value: "green"},
              {label: "Blue", value: "blue"}
          ]
      },'wow.$': {
          type: String
      },
      }});
      

      但是现在,它只是将值保存在 MongoDB 中,如何保存标签和值?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-24
        • 2014-10-13
        • 1970-01-01
        • 2017-03-15
        • 2015-06-24
        相关资源
        最近更新 更多