【问题标题】:object and file upload fields are not showing对象和文件上传字段未显示
【发布时间】:2015-10-25 14:04:50
【问题描述】:

这是我的架构但是没有显示带有字段名称和数量的成分对象,也没有显示我的图片上传文件。那么你能告诉我我的错误以及如何纠正它吗?

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}}

【问题讨论】:

    标签: javascript meteor meteor-autoform meteor-collection2


    【解决方案1】:

    首先,模式定义不正确。如果您想让ingredients 属性成为对象数组,您需要将type 定义为数组,如下所示:

    ingredients: {
        type: [Object],
        label:"Ingredients",
        minCount: 1
    }
    

    然后,在您的模板中,您的属性名称使用大写 I,而不是小写,因为它在架构中定义。把名字改成ingredients

    {{> afQuickField name='ingredients'}}
    

    您不需要在模板中包含ingredients 的子属性。 Autoform 将自动为对象数组的子属性创建 UI。

    对于文件上传,输入类型必须与架构中的定义相匹配。尝试将模板中的字段定义更改为:

    {{> afFieldInput name='image'}}
    

    【讨论】:

      猜你喜欢
      • 2020-09-22
      • 1970-01-01
      • 2013-03-10
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多