変数の属性が変更されたときにエラーをログに記録しようとしていますが、検証がトリガーされることはありません。これが私のコードです:
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 を使用しています。