benhowdle89
benhowdle89

Reputation: 37464

Model Attributes not being set by Collection.fetch() in Backbone

I have this code:

app.Collections.quotes = new app.Collections.Quotes();
    app.Collections.quotes.fetch({
        success: function(){
            console.log(app.Collections.quotes.at(0).get("NetAmount"));
        }
    });

Console.log returns 'undefined'.

Yet, I can see the returned response from the server is an array of Objects and Backbone does actually create 27 models, but none of them have any attributes!

Any ideas?

Upvotes: 1

Views: 988

Answers (1)

jevakallio
jevakallio

Reputation: 35890

As per question comments, it looks like you may have overridden Model.parse. If you do, you need to return the attributes hash you want to set as the model's attributes:

parse: function(response) {
  //do something with response
  return response;
}

Upvotes: 2

Related Questions