我在下面粘贴了我的代码,当数据被推入模型中已经存在的数组时,“更改时”不会触发,但是当整个数组被重置时,它会被触发。
var BookModel = Backbone.Model.extend({
defaults : {
"subject" : [0,4]
},
initialize : function() {
this.on('change',this.fetchResults);
},
fetchResults : function() {
console.log("fetch");
}
});
var myModel = new BookModel();
var subjects = myModel.get('subject');
subjects.push(2); //fetch does not get called
//subjects = []; //fetch gets called
myModel.set({"subject": subjects});
小提琴:http: //jsfiddle.net/WnNQk/