Reputation: 1367
My server response is having two objects (picture):
How can i put just secound object members (models) in my Backbone Collection. I am using collection.fetch to get data from server. Can I somehowe addapt my server response.
Upvotes: 3
Views: 1714
Reputation: 2232
use parse()
see: http://backbonejs.org/#Collection-parse
in your collection:
yourCollection = Backbone.Collection.extend({
//other collection stuff.
parse: function(response) {
//save the search metadata in case you need it later
this.search_meatadata = response["search_metadata"];
// return the array of objects.
return response["statuses"];
}
});
Upvotes: 2
Reputation: 1999
You can do this by overriding the parse method of your collection:
var coll = Backbone.Collection.extend({
parse: function(data){
return data.statuses;
}
});
Your Collection will contain what you return from your parse function, in this case you reduce it to the statuses array from your server response.
Upvotes: 7