我正在获取验证日志“这是否正在工作”,如果我在if语句中输入日志,我也会得到它。它似乎没有触发this.on('invalid')事件。有什么原因吗?
var Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
},
validate: function(attrs){
console.log("IS THIS EVEN WORKING");
if(attrs.title == '' || !attrs.title){
return "ya gone done messed it up";
}
},
initialize: function(){
console.log('todo model created'),
/*this.on('change:title', function(){
console.log(this.get('title') + 'values have changed');
});*/
this.on("invalid", function(model, error){
console.log(error);
})
}
});
var todo2 = new Todo({
completed:true
});
todo2.set('completed', false, {validate:true});
console.log(todo2.get('completed'));