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