Meteor:带有对象数组的自定义 AutoForm [英] Meteor: Custom AutoForm with array of objects

查看:15
本文介绍了Meteor:带有对象数组的自定义 AutoForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含对象数组的 SimpleSchema:

I have a SimpleSchema which includes an array of objects:

Things.attachSchema( new SimpleSchema({
    name: {
        type: String,
        label: "Name",
        max: 50
    },
    fields: { 
        type: [Object],
    },
    fields.$.name: {
        type: String
    },
    fields.$.amount: {
        type: Number
    }
}) )

我正在尝试使用 afEachArrayItem 创建自定义表单,但我不知道如何引用数组中每个对象的属性.

I'm trying to create custom form making use of afEachArrayItem, but I can't work out how to refer to the attributes of each object within the array.

我的模板看起来像这样(去掉了 html):

My template looks like this (with html stripped out):

{{#autoForm collection="things" id="myForm" }}
    {{> afQuickField name='schemaName'}}

    {{#afEachArrayItem name="fields"}}

        {{> afFieldInput name="name"}  
        {{> afFieldInput name="amount"}

    {{/afEachArrayItem}}

{{/autoForm}}

应该将什么传递给 afFieldInputs 中的name"?

What should be passed to "name" in the afFieldInputs?

推荐答案

要访问数组内对象的字段,可以使用:

To access the fields of the objects within the array, you can use:

this.current

因此要修复上面给出的示例,请使用:

So to fix the example given above, use:

{{#autoForm collection="things" id="myForm" }}
    {{> afQuickField name='schemaName'}}

    {{#afEachArrayItem name="fields"}}

        {{> afFieldInput name=this.current.name}}  
        {{> afFieldInput name=this.current.amount}}

    {{/afEachArrayItem}}

{{/autoForm}}

我不知道这是否是正确的方法,但它似乎有效.

I don't know if this is the correct way to do this, but it seems to work.

这篇关于Meteor:带有对象数组的自定义 AutoForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆