Meteor自动表单更新嵌套集合
我试图创建一个表单,以便在集合的嵌套数组中插入新元素。 以下是我的模式:Meteor自动表单更新嵌套集合,meteor,collections,nested,meteor-autoform,Meteor,Collections,Nested,Meteor Autoform,我试图创建一个表单,以便在集合的嵌套数组中插入新元素。 以下是我的模式: Schemas.CampaignsSchema = new SimpleSchema({ 'name': { type: String } }); Schemas.ElectionsSchema = new SimpleSchema({ 'campaigns': { type: [Schemas.CampaignsSchema], defaultValue: [] } });
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>
Template.campaignsNew.helpers({
schema(){return Schemas.CampaignsSchema;},
});
{{#自动成型
“选举”征集
模式=模式
doc=doc
活动范围’
id='insertCampaignForm'
type='update-pushArray'}}
添加活动
{{>afQuickField name='campaiments.$.name'}
插入
{{/autoForm}
所以一个字段是由autoform生成的,但是当我点击submit时什么也没有发生
如果启用Autoform.debug(),我会得到:
SimpleSchema.clean:筛选出会影响键“活动”的值,这是架构不允许的
SimpleSchema.clean:筛选出可能会影响键“活动.$”的值,架构不允许该值
SimpleSchema.clean:筛选出可能会影响键“campaigns.$.name”的值,这是架构不允许的
有人知道吗?似乎
#autoform
的schema
属性与类型update pushArray
不兼容
以下是使用代码reste的模板:
<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>
{{#自动成型
“选举”征集
doc=选举
id='insertCampaignForm'
type='update-pushArray'
scope='campaiments'}
添加活动
{{>afquickfieldname='name'}
插入
{{/autoForm}
唯一的问题是,名称
字段预先填充了选择
名称
似乎嵌套文档不能有与主文档同名的字段
但是,创建的嵌套文档具有良好的名称,而主文档的名称保持不变