流星:自定义自动窗体与对象数组 [英] Meteor: Custom AutoForm with array of objects
本文介绍了流星:自定义自动窗体与对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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被传递到名?
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.
这篇关于流星:自定义自动窗体与对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文