在Meteor Simple Schema中为AutoForm选项值获取标签

时间:2015-10-03 07:41:27

标签: meteor meteor-autoform simple-schema

在Meteor模板{{parameter}}中返回此架构的选项值:

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

1 个答案:

答案 0 :(得分:3)

Template.yourTemplate.helpers({
  label: function (value) {
    return _.findWhere(YourSchema.schema('parameter').autoform.options, { value: value }).label;
  }
});