我正在尝试使用backbone.js model.set 属性。在执行 todo1.set 后,第二个警报功能应该触发。然而事实并非如此。
这是 jsfiddle 链接:http: //jsfiddle.net/SGEkn/
var Todo = Backbone.Model.extend({
defaults: {
title: "Harsh",
completed: false
},
initialize: function() {
console.log('This model has been initialized.')
}
});
var todo2 = new Todo({
title: 'Set through instantiation.',
completed: true
});
console.log('Todo title: ' + todo2.get('title'));
console.log('Todo completed ' + todo2.get('completed'));
alert("ok");
todo2.set("title", 'Title set');
alert("ok");
console.log(todo2.get('title'));
todo.set("completed", false);
console.log('completed: ' + todo2.get('completed'));