[英]Validate backbone Model WIth Nested Object
I have on model and have some fields in that and one oject that has some more fields,and i am validate that using backbone validatation,validation working fine for name and age but for field in object(address) validation is not working. 我在模型上有一个字段,在那个字段中有一个字段,而另一个对象还有更多字段,我验证使用主干验证,对于名称和年龄的验证工作正常,但对于对象(地址)的验证工作不正常。
How to validate field in address? 如何验证地址中的字段?
Ex. 例如
var PersonModel = Backbone.Model.extend({
defaults: {
name: null,//String
age: null,//Integer
address: {
pincode : null,
streetName : ''
}
}
validation: {
name: {
required: true
},
age: {
range: [1, 80]
},
address : {
pincode :{
required : true
}
}
}
});
Thanks In advance 提前致谢
In the Backbone.Validation documentation it says that : 在Backbone.Validation文档中说:
"Validating complex objects is also supported. To configure validation rules for objects, use dot notation in the name of the attribute, eg 'address.street'." “还支持验证复杂对象。要为对象配置验证规则,请在属性名称中使用点符号,例如'address.street'。”
Hence in your case, for the validation of properties in address object it should be : 因此,在您的情况下,为了验证地址对象中的属性,应该为:
"address.pincode" : {
required : true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.