[英]object and file upload fields are not showing
這是我的模式,但是沒有顯示其字段名稱和數量的配料對象,也沒有顯示我上傳的圖像。那么你能告訴我我的錯誤以及如何糾正它嗎?
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'}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.