Meteor Autoform更新嵌套集合

时间:2015-11-11 21:59:37

标签: meteor collections nested meteor-autoform

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

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生成一个字段,但是当我点击提交时没有任何反应。

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

  

SimpleSchema.clean:过滤掉会影响关键“广告系列”的值,模式不允许这样做

     

SimpleSchema.clean:过滤掉会影响关键“广告系列。$”的值,这是模式不允许的

     

SimpleSchema.clean:过滤掉会影响关键“广告系列。$。name”的值,这是模式不允许的

有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

似乎schema的{​​{1}}属性不适用于#autoform类型。

以下是与代码重新使用的模板:

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名称...

您的嵌套文档似乎没有与主文档同名的字段。

然而,创建的嵌套文档具有良好的名称,主文档的名称保持不变。