创建一个数组形式,其中每个元素都是 'select' 类型
Creating an array form where each element is a 'select' type
我在我的 meteor 项目上使用自动表单,并且在我的 NewStack
表单中的 dimensions
字段中使用 afArrayField
。
目前看起来像这样。
这是它的渲染方式:
NewStack.html
<template name="NewStack">
<div class="new-stack-container">
{{#autoForm collection=stacks id="insertStackForm" type="method" meteormethod="createStack" class="new-stack-form"}}
<fieldset>
<legend>Add a Stack!</legend>
{{> afQuickField name='desc'}}
{{> afArrayField name='dimensions'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}
</div>
</template>
对于每个维度字段,我希望看到的是一个下拉列表,其中填充了我在架构中设置的选项(即 dim1
、dim2
和 dim3
) .但是我似乎无法让表单呈现为纯文本输入以外的任何形式。
Stacks.js
StackSchema = new SimpleSchema({
desc: {
type: String,
label: "Description"
},
dimensions: {
type: [String],
autoform: {
type: "select",
afFieldInput: {
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
]
},
}
}
});
有趣的是,如果我将 NewStack.html 中的 afArrayField
更改为 afQuickField
似乎自动表单现在可以看到我的选项(但我显然失去了数组功能)
有什么想法吗? afArrayField
是否有某些内在因素阻止我使用某种选择模式?
尝试将架构更改为:
dimensions: {
type: [String],
autoform: {
type: "select",
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
],
}
您可以使用 $
:
为数组中的每个元素指定选项
const StackSchema = new SimpleSchema({
desc: {
type: String,
label: "Description"
},
dimensions: {
type: [String],
},
"dimensions.$": { // note this entry
type: String,
autoform: {
afFieldInput: {
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
]
},
}
}
});
它在自动表单中提到 docs。
我在我的 meteor 项目上使用自动表单,并且在我的 NewStack
表单中的 dimensions
字段中使用 afArrayField
。
目前看起来像这样。
这是它的渲染方式:
NewStack.html
<template name="NewStack">
<div class="new-stack-container">
{{#autoForm collection=stacks id="insertStackForm" type="method" meteormethod="createStack" class="new-stack-form"}}
<fieldset>
<legend>Add a Stack!</legend>
{{> afQuickField name='desc'}}
{{> afArrayField name='dimensions'}}
</fieldset>
<button type="submit" class="btn btn-primary">Insert</button>
{{/autoForm}}
</div>
</template>
对于每个维度字段,我希望看到的是一个下拉列表,其中填充了我在架构中设置的选项(即 dim1
、dim2
和 dim3
) .但是我似乎无法让表单呈现为纯文本输入以外的任何形式。
Stacks.js
StackSchema = new SimpleSchema({
desc: {
type: String,
label: "Description"
},
dimensions: {
type: [String],
autoform: {
type: "select",
afFieldInput: {
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
]
},
}
}
});
有趣的是,如果我将 NewStack.html 中的 afArrayField
更改为 afQuickField
似乎自动表单现在可以看到我的选项(但我显然失去了数组功能)
有什么想法吗? afArrayField
是否有某些内在因素阻止我使用某种选择模式?
尝试将架构更改为:
dimensions: {
type: [String],
autoform: {
type: "select",
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
],
}
您可以使用 $
:
const StackSchema = new SimpleSchema({
desc: {
type: String,
label: "Description"
},
dimensions: {
type: [String],
},
"dimensions.$": { // note this entry
type: String,
autoform: {
afFieldInput: {
options: [
{label: "dim1", value: 1},
{label: "dim2", value: 2},
{label: "dim3", value: 3}
]
},
}
}
});
它在自动表单中提到 docs。