Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor AutoForm-具有数组索引的字段名无效_Meteor - Fatal编程技术网

Meteor AutoForm-具有数组索引的字段名无效

Meteor AutoForm-具有数组索引的字段名无效,meteor,Meteor,我在我的简单模式中得到了: "servicesSelected.0.sku" : { type: String, optional: true }, 基本上,我希望选中的服务的第一个数组项中的sku键是一个字符串,并且是可选的 这是我的表单代码,用于复选框 {{> afFieldInput class="track-order-change" type="checkbox" checkbox="true" template="" name="servicesS

我在我的简单模式中得到了:

  "servicesSelected.0.sku" : {
    type: String,
    optional: true
  },
基本上,我希望选中的
服务的第一个数组项中的
sku
键是一个字符串,并且是可选的

这是我的表单代码,用于复选框

  {{> afFieldInput class="track-order-change" type="checkbox" checkbox="true" template="" name="servicesSelected.0.sku" value="hdrPhotos"}}
我得到的错误是无效的字段名“servicesSelected.0.sku”

一旦我删除了模式和afFieldInput中的数组索引,错误就会消失,但关键是要验证数组索引0中的数据

我将假设它是无效的,因为在JS中,如果使用点表示法,则不能将数字作为键名的第一个字符


但是简单模式和自动格式不支持方括号表示法…

我不确定SimpleSchema是否允许您验证这样的数组。可能需要自定义验证

我知道这里的想法是数组的第一个元素可以具有
sku
属性,但其他元素不能。在这种情况下,请尝试以下方法:

servicesSelected: {
  type: [selectedServiceSchema],
  custom: function() {
    for(var i=1; i<this.value.length; ++i) {
      if(this.value[i].sku) return "SKU set in the wrong service";
    }
  },
},
已选择服务:{
类型:[selectedServiceSchema],
自定义:函数(){
对于(var i=1;i