我计划使用http://thedersen.com/projects/backbone-validation/#examples进行模型/表单验证。但模型继续保存,而表单无效。有什么问题?
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
M=Backbone.Model.extend({
validation:{
name:{
required:true
}
},
url:'foo'
})
m=new M();
m.validate(); //return correct validation error.
m.validationError; // this is null while it should be filled by above error
m.save(); // it communicate with server while the model is not valid
答案 0 :(得分:0)
尚未设置属性名称。请尝试以下代码。
M = Backbone.Model.extend({
defaults: {
name: null
},
validation:{
name:{
required:true
}
},
url:'foo'
});