I'm trying to use backbone.js model.set property. The second alert function should fire off after todo1.set is being implemented. However it is not.
Here is the jsfiddle link: 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'));
You should be passing an object and not the arguments individually.
todo2.set({"title":'Title set'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With