这是我的架构,但是成分对象及其字段名称和金额没有显示,而且我的图像上传文件也没有显示。那么你能告诉我我的错误以及如何纠正它吗?
Recipes.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Recipe Name",
max: 100
},
ingredients: {
type: Object,
label:"Ingredients",
minCount: 1
},
"ingredients.$.name": {
type: String
},
"ingredients.$.amount": {
type: String
},
description: {
type: String,
label: "How to prepare ",
},
time: {
type: Number,
label: "Time (Minutes)",
},
image: {
type: String,
autoform: {
afFieldInput: {
type: 'fileUpload',
collection: 'RecipesImages',
label: 'Recipe Picture'
}
}
},
createdAt: {
type: Date
}
}));
在这里,我将它们与自动表单一起放入我的模板中
{{#autoForm collection="Recipes" id="insertRecipes" type="insert"}}
<fieldset>
<legend>Add a Recipe</legend>
{{> afQuickField name='name'}}
{{> afQuickField name='Ingredients'}}
{{> afQuickField name='Ingredients.name'}}
{{> afQuickField name='Ingredients.amount'}}
{{> afQuickField name='description' rows=6}}
{{> afQuickField name='time'}}
{{> afQuickField name='image'}}
</fieldset>
<button type="submit" class="btn btn-primary">Add Recipe</button>
{{/autoForm}}
最佳答案
首先,架构定义不正确。如果您想让 ingredients
属性成为一个对象数组,您需要将 type
定义为数组,如下所示:
ingredients: {
type: [Object],
label:"Ingredients",
minCount: 1
}
然后,在模板中,属性名称使用大写 I,而不是小写,如架构中定义的那样。将名称更改为ingredients
{{> afQuickField name='ingredients'}}
您不需要在模板中包含 ingredients
的子属性。 Autoform 将自动为对象数组的子属性创建 UI。
对于文件上传,输入类型必须与架构中的定义匹配。尝试将模板中的字段定义更改为:
{{> afFieldInput name='image'}}
关于javascript - 对象和文件上传字段未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33330564/