创建带有单选按钮数组的meteor autoform

时间:2015-06-15 04:03:47

标签: meteor meteor-autoform

我想在流星中构建一个autoform,为用户提供12个单选按钮,并为12个按钮中的每个按钮记录一个条目。如果我创建12个不同的按钮,我可以很容易地使表单工作 - 见下文,但我想知道是否有可能创建一个数组来更容易地做到这一点。

Homework = new Mongo.Collection("homework");
Homework.attachSchema(new SimpleSchema({
userId:{
    type: String,
    autoValue:function(){return this.userId},

},
userName:{
    type: String,
    autoValue:function(){return Meteor.users.findOne({_id: this.userId}).emails[0].address},
},
fName:{
    type: String,
    autoValue:function(){return Meteor.users.findOne({_id: this.userId}).profile.fName},
},
lName:{
    type: String,
    autoValue:function(){return Meteor.users.findOne({_id: this.userId}).profile.lName},
},

page: {
    type: Number,
    label: "Page Number",
    max: 200
},
problem1: {
    type: Boolean,
},
problem2: {
    type: Boolean,
},
problem3: {
    type: Boolean,
},
problem4: {
    type: Boolean,
},
problem5: {
    type: Boolean,
},
problem6: {
    type: Boolean,
},
problem7: {
    type: Boolean,
},
problem8: {
    type: Boolean,
},
problem9: {
    type: Boolean,
},
problem10: {
    type: Boolean,
},
problem11: {
    type: Boolean,
},
problem12: {
    type: Boolean,
},

}));

1 个答案:

答案 0 :(得分:0)

烨!您可以使用以下表示法在SimpleSchema中简单地定义数组:

...

  'problems': {
    type: String,
    autoform: {
      afFieldInput: {
        options: function () { return {
          one: 'one',
          two: 'two',
          three: 'three',
          four: 'four',
          five: 'five',
          six: 'six',
        } }
      }
    }
  }

...

在你的模板中

{{ > afQuickField name="problems" noselect=true }}