RuntimeException
RuntimeException

Reputation: 1135

Backbone model not getting updated

I have this model in backbone app:

var dimensions = Backbone.Model.extend({
    defaults: {
        a: 10,
        f: 1,
        g: 1
    }
});

Then I'm updating this model data from server using model.fetch(); which is returning following:

{
    f: 10,
    g: 2,
    h: 3            
}

It seems like mode is not getting updated as it is still giving me following output :

dimensions.get('a'); //10; 

Upvotes: 0

Views: 25

Answers (1)

Gurpreet Singh
Gurpreet Singh

Reputation: 21233

You are getting expected result, model.fetch(); will not clear out your model, but rather extends the attributes of your model. So, after fetch your model looks like this:

{
    a: 10,
    f: 10,
    g: 2,
    h: 3
}

That's why you are getting 10 for a. You can use dimentions.clear(); is you intend to clear model attributes.

Upvotes: 1

Related Questions