使用单选按钮数组创建流星自动表单

Creating meteor autoform w/ array of radio buttons

我想在 meteor 中构建一个自动窗体,向用户显示 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,
},

}));

是啊!您可以使用以下表示法在 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 }}