在自动表单中同时使用 "collection" 和 "schema" 属性
using both of "collection" and "schema" attribute in autoform
我在 mongoDB 中有一个 "Ads" 集合,但以下格式的模式过多:
AdsBaseSchema = new SimpleSchema({
_parentId: {
type: String,
optional: true
},
title: {
type: String,
label: "Title",
max: 200
}
description: {
type: String,
label: "Description",
optional: true
}
});
但它们在某些字段上有所不同。
我想将它们用于插入自动表单。像这样:
{{> quickForm schema="AdsBaseSchema" id="insBaseAds" type="method" meteormethod="insBaseAds"}}
用这个方法:
insBaseAds: function(doc) {
Ads.insert(doc);
this.unblock();
}
这种方法是正确的!但这是我的问题:
我很难将这种方法用于我的所有模式! (正如我所说,因为我有太多模式)
我想问你:
meteor 是否可以使用类似下面的自动表单,并且只对所有模式使用一个自动表单(表单生成器)?
{{> quickForm collection="Ads" schema="AdsBaseSchema" id="insertAds" type="insert"}}
是否可以在自动表单中同时使用"collection"和"schema"属性?
我找到了这个问题的解决方案:
我可以尝试为我的模板编写一个助手,其中 returns 一个动态的模式名称,如下所示:
{{> quickForm collection="Ads" schema=schema id="insertAds" type="insert"}}
帮手:
Template['myTemplate'].helpers({
schema() {
//Write your logic here
return "adsBaseSchema";
}
})
幸运的是它起作用了。
我在 mongoDB 中有一个 "Ads" 集合,但以下格式的模式过多:
AdsBaseSchema = new SimpleSchema({
_parentId: {
type: String,
optional: true
},
title: {
type: String,
label: "Title",
max: 200
}
description: {
type: String,
label: "Description",
optional: true
}
});
但它们在某些字段上有所不同。
我想将它们用于插入自动表单。像这样:
{{> quickForm schema="AdsBaseSchema" id="insBaseAds" type="method" meteormethod="insBaseAds"}}
用这个方法:
insBaseAds: function(doc) {
Ads.insert(doc);
this.unblock();
}
这种方法是正确的!但这是我的问题:
我很难将这种方法用于我的所有模式! (正如我所说,因为我有太多模式)
我想问你:
meteor 是否可以使用类似下面的自动表单,并且只对所有模式使用一个自动表单(表单生成器)?
{{> quickForm collection="Ads" schema="AdsBaseSchema" id="insertAds" type="insert"}}
是否可以在自动表单中同时使用"collection"和"schema"属性?
我找到了这个问题的解决方案:
我可以尝试为我的模板编写一个助手,其中 returns 一个动态的模式名称,如下所示:
{{> quickForm collection="Ads" schema=schema id="insertAds" type="insert"}}
帮手:
Template['myTemplate'].helpers({
schema() {
//Write your logic here
return "adsBaseSchema";
}
})
幸运的是它起作用了。