无法读取未定义的属性'blackbox' - AutoForm和Meteor

时间:2014-07-14 14:11:42

标签: meteor

这是我的架构:

TestCollection = new Meteor.Collection('test_collection');

var Schemas = {};

Schemas.TestCollection = new SimpleSchema({

  servicesSelected: {
    type: [Object]
  },

  "servicesSelected.0.selected" : {
    type: Boolean,
    optional: false
  },
  "servicesSelected.0.sku" : {
    type: String,
    optional: true
  },
  "servicesSelected.0.title" : {
    type: String,
    optional: true
  },
  "servicesSelected.0.price": {
    type: Number,
    optional: true
  },
  "servicesSelected.1.selected" : {
    type: Boolean,
    optional: false
  },
  "servicesSelected.1.sku" : {
    type: String,
    optional: true
  },
  "servicesSelected.1.title" : {
    type: String,
    optional: true
  },
  "servicesSelected.1.price": {
    type: Number,
    optional: true
  }

});

TestCollection.attachSchema(Schemas.TestCollection);

我的模板:

<template name="test">

{{#autoForm validation="keyup" collection="TestCollection" id="order-submission-test-form" type="insert"}}

    <h1>Doing everything manually and specifying the data-schema-key:</h1>

    <input type="checkbox" name="servicesSelected.0.selected" data-schema-key="servicesSelected.0.selected">
    <label>HDR Photos</label>

    <input type="checkbox" name="servicesSelected.1.selected" data-schema-key="servicesSelected.1.selected">
    <label>Panos</label>

{{/autoForm}}

</template>

每当我点击复选框或尝试验证表单时,我都会收到无法读取的属性&#39; blackbox&#39;控制台中的未定义错误我究竟做错了什么?

servicesSelected应该是一个包含每个索引上的哈希表的数组。

类似于:

serviceSelected = [

  { 
    selected: true,
    sku: "123",
    title: "title1",
    price: 100 
  },

  { 
    selected: false,
    sku: "124",
    title: "title2",
    price: 150 
  }
]

1 个答案:

答案 0 :(得分:0)

刚刚遇到同样的问题,我会尝试删除子对象定义中的所有数字。所以我会尝试"servicesSelected.$.selected"代替"servicesSelected.0.selected"

为我工作,希望它可以解决这个奇怪的问题。