获取 Meteor Simple Schema 中 AutoForm 选项值的标签
Get label for AutoForm option value in Meteor Simple Schema
在 Meteor 模板中 {{parameter}}
returns 此架构的选项值:
new SimpleSchema({
parameter: {
type: String,
allowedValues: ['value_1', 'value_2'],
autoform: {
options: [
{label: "label_1", value: 'value_1'},
{label: "label_2", value: 'value_2'}
]
}
},
});
如何在我的模板中得到 label
而不是 value
?
Template.yourTemplate.helpers({
label: function (value) {
return _.findWhere(YourSchema.schema('parameter').autoform.options, { value: value }).label;
}
});
在 Meteor 模板中 {{parameter}}
returns 此架构的选项值:
new SimpleSchema({
parameter: {
type: String,
allowedValues: ['value_1', 'value_2'],
autoform: {
options: [
{label: "label_1", value: 'value_1'},
{label: "label_2", value: 'value_2'}
]
}
},
});
如何在我的模板中得到 label
而不是 value
?
Template.yourTemplate.helpers({
label: function (value) {
return _.findWhere(YourSchema.schema('parameter').autoform.options, { value: value }).label;
}
});