0
我想记录一个错误工作时可变的属性发生变化,但验证永远不会被触发,这是我的代码:验证功能没有在骨干
Person = Backbone.Model.extend({
initialize: function() {
console.log("hello world");
this.bind('change:name', function() {
console.log(this.get('name') + ' is now the value for the name');
});
this.bind('error', function(model, error) {
console.log(error);
});
},
defaults: {
name: 'Bob Hope',
height: 'unknown'
},
validate: function(attributes) {
if(attributes.name == 'blank'){
return 'no';
}
}
});
var person = new Person();
person.set({name: 'blank'});
我甚至试试这样设置:
person.set({name: 'blank'}, {validate: true});
但这也行不通,我使用的是1.0.0版本。