Meteor Autoform更新嵌套集合

Meteor Autoform update a nested collection

我正在尝试创建一个表单,以便在集合的嵌套数组中插入一个新元素。 这是我的模式:

Schemas.CampaignsSchema = new SimpleSchema({
  'name': {
    type: String
  }
});
​
Schemas.ElectionsSchema = new SimpleSchema({
  'campaigns': {
    type: [Schemas.CampaignsSchema],
    defaultValue: []
  }
});

这是我的模板:

Template.campaignsNew.helpers({
  schema() { return Schemas.CampaignsSchema; },
});
​
​
<template name="campaignsNew">
  {{#autoForm
    collection='Elections'
    schema=schema
    doc=doc
    scope='campaigns'
    id='insertCampaignForm'
    type='update-pushArray'}}
    <fieldset>
      <legend>Add a Campaign</legend>
      {{> afQuickField name='campaigns.$.name'}}
    </fieldset>
    <button type="submit" class="btn btn-primary">Insert</button>
  {{/autoForm}}
</template>

所以一个字段是由自动表单生成的,但是当我点击提交时没有任何反应。

如果我启用 Autoform.debug() 我得到:

SimpleSchema.clean: filtered out value that would have affected key "campaigns", which is not allowed by the schema

SimpleSchema.clean: filtered out value that would have affected key "campaigns.$", which is not allowed by the schema

SimpleSchema.clean: filtered out value that would have affected key "campaigns.$.name", which is not allowed by the schema

有人知道吗?

#autoformschema 属性似乎不适用于类型 update-pushArray

这是与代码的其余部分一起使用的模板:

<template name="campaignsNew">
  {{#autoForm
    collection='Elections'
    doc=election
    id='insertCampaignForm'
    type='update-pushArray'
    scope='campaigns'}}
    <fieldset>
      <legend>Add a Campaign</legend>
      {{> afQuickField name='name'}}
    </fieldset>
    <button type="submit" class="btn btn-primary">Insert</button>
  {{/autoForm}}
</template>

唯一的问题是 name 字段预先填充了 Election 名称...

看来您的嵌套文档不能有与主文档同名的字段。

但创建的嵌套文档名称良好,主文档名称保持不变