Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone.js model.set is not working [closed]

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'));
like image 698
user1801879 Avatar asked Jun 08 '13 20:06

user1801879


1 Answers

You should be passing an object and not the arguments individually.

todo2.set({"title":'Title set'});
like image 139
Matt Whipple Avatar answered Sep 30 '22 13:09

Matt Whipple