【问题标题】:Meteor Autoform update a nested collectionMeteor Autoform 更新嵌套集合
【发布时间】:2016-02-13 03:22:39
【问题描述】:

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

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:过滤掉会影响键“活动”的值,这是架构不允许的

SimpleSchema.clean:过滤掉会影响键“campaigns.$”的值,这是架构不允许的

SimpleSchema.clean:过滤掉会影响键“campaigns.$.name”的值,这是架构不允许的

有人知道吗?

【问题讨论】:

    标签: meteor collections nested meteor-autoform


    【解决方案1】:

    似乎#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 名称...

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 2015-06-22
      • 1970-01-01
      • 2021-12-05
      相关资源
      最近更新 更多