vovacodes
vovacodes

Reputation: 525

Backbone.Model. Replace attributes hash

Is there any options for set method or any other way to replace the current attributes of the model with ones provided? Here is what I want:

var instance = new Backbone.Model();

instance.set({foo: 1});
instance.set({bar: 2}, {replace: true}); //just for example

console.log(instance.toJSON()); //returns {bar: 2}

Upvotes: 2

Views: 964

Answers (2)

Ravi Hamsa
Ravi Hamsa

Reputation: 4721

If you want to clear just one attribute, you can use

instance.unset('foo').set({bar:2})

Upvotes: 0

Vitalii Petrychuk
Vitalii Petrychuk

Reputation: 14225

I guess you are looking for this: http://backbonejs.org/#Model-clear

instance.clear().set({bar: 2});

Upvotes: 2

Related Questions