如何使用 AutoForm 将新对象添加到数组中?

How to add new object into Array using AutoForm?

我的简单架构如下所示:

Schema = new SimpleSchema
  name:
    label: "Order title"
    type: String
    optional: true

  offers:
    type: Array
    optional: true
  'offers.$':
    type: Object
  'offers.$.name':
    type: String
    min: 3
  'offers.$.selected':
    type: Boolean
    defaultValue: false

首先,我要在 Mongo 集合中插入新条目。那个,当我已经有了它的时候,我想再添加一个报价。

我已经尝试使用此代码将新报价添加到报价数组中,但它没有将任何数据发送到方法中

+autoForm id="addOffer" schema=Schema type="method" meteormethod="addOffer" doc=data
  +afQuickField name='offers.$'
  button(type="submit") Add

看来,我只能一次编辑所有这些。例如。使用:

+autoForm id="updateOffer" collection="Order" type="update" doc=data
  +afQuickField name='offers'

如果我想使用 autoForm 添加新的报价而不看到已添加的报价,我是否应该将报价移到单独的集合中?

使用 arrayTracker.addOneToField 应该可以完成工作。在此处查看此事件处理程序:https://github.com/aldeed/meteor-autoform/blob/master/autoform-events.js#L474

似乎 aldeed 刚刚解决了新 AutoForm (5.0) 版本中的问题。现在我们有 update-pushArray 表单类型。

更多信息在这里:https://github.com/aldeed/meteor-autoform#update-pusharray