【发布时间】:2016-08-04 08:04:29
【问题描述】:
我有两种形式和两种模式,它们没有任何共同之处。但我仍然需要将它们存储在同一个集合中。
例如:
schema1 = new SimpleSchema({ field1, field2, field3 });
collection.attachSchema(schema1);
schema2 = new SimpleSchema({ fieldX, fieldY, fieldZ });
collection.attachSchema(schema2);
从Collection2 documentation了解到,上述方法实际上会将两个模式合并为一个大模式。这意味着两个表单都必须具有属于两个架构的所有字段。
这意味着我不能有一个只有 schema1 的 autoForm 和另一个只有 schema2 的 autoform。
根据文档,我尝试实现 replace: true - 每次都会覆盖架构。 (至少我是这样理解的——它们不会合并到一个大模式中)
例如:
schema1 = new SimpleSchema({ field1, field2, field3 });
collection.attachSchema(schema1, {replace: true});
schema2 = new SimpleSchema({ fieldX, fieldY, fieldZ });
collection.attachSchema(schema2 {replace: true});
以上内容仍然无法解决问题,并且不知何故,模式仍然被合并。意思是,即使没有填写 fieldX 的规定,我仍然会收到 autoform1 中 FieldX 为空白的通知。
我还尝试了另一种使用变体的方法。
例如:
schema1 = new SimpleSchema({ field1, field2, field3 });
collection.attachSchema(schema1, {selector: {type: 'forForm1'}});
schema2 = new SimpleSchema({ fieldX, fieldY, fieldZ });
collection.attachSchema(schema2, {selector: {type: 'forForm2'}});
当我实现上述内容时,我收到一个自动生成错误,指出在处理多个模式时必须将参数传递给 doc。
我该如何做呢?
文档特别指出:
现在两个模式都已附加。当您插入文档时,键入: 'simple' 在文档中,它将仅针对 简单产品架构。当您插入文档时,类型:'variant' 在文档中,它将仅针对 VariantProductSchema。
我不知道我需要如何传递 doc = ????在模板中。有人可以指导我吗?
这是我的自动生成模板:
Form1:
{{#autoForm collection = "pgTemplates" type ="insert" doc= ???? id ="InsertForm1" }}
{{#each afFieldNames}}
{{> afQuickField name=this.name options = afOptionsFromSchema }}
{{/each}}
Form2:
{{#autoForm collection = "pgTemplates" type ="insert" doc= ???? id ="InsertForm1" }}
{{#each afFieldNames}}
{{> afQuickField name=this.name options = afOptionsFromSchema }}
{{/each}}
【问题讨论】:
标签: meteor meteor-autoform meteor-collection2 simple-schema