backbone.js model.set is not working
16,578
You should be passing an object and not the arguments individually.
todo2.set({"title":'Title set'});
Author by
user1801879
Updated on June 18, 2022Comments
-
user1801879 almost 2 years
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'));