javascript - 对象和文件上传字段未显示

标签 javascript meteor meteor-autoform meteor-collection2

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

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/

相关文章:

javascript - JS 正则表达式匹配特殊字符

javascript - getElementById 在文本框中不起作用?

javascript - 通过单击按钮引用 li 的跨度

security - meteor ddp 连接安全和 https

javascript - 如何检查 Meteor 中的自定义验证简单模式中的 bool 值是否为 true

javascript - 如何将图像从 autoform 链接到 CollectionFS 中的用户集合以显示个人资料图片?

javascript - 插入失败: Error: Title is required

javascript - OOP Node.js 框架 Danf 是否确保了接口(interface)?

javascript - 如何从 Meteor 0.8.0 Blaze 中的助手访问模板实例

node.js - 将旧的 1.2 meteor 项目升级到最新版本 1.6 的最佳方法是什么?