I am trying to get this to work, but I am struggling with it. My collection ends up empty when I check the success callback on fetch . This does not give me any obvious errors during parse . Here is my code:
My collection:
VOR.Collections.GridItems = Backbone.Collection.extend({ model : VOR.Models.GridItem, url: "assets/data/grid.json", parse: function(response){ var self = this; _.each(response, function(griditem){ switch(griditem.type){ case "news": self.add(new VOR.Models.NewsGridItem(griditem)); break; default: self.add(new VOR.Models.StandardGridItem(griditem)); break; } }); } });
This is how I create the collection:
griditems = new VOR.Collections.GridItems(); griditems.fetch({ error: function(e) {console.log(e);}, success: function(msg) { console.log(msg) });
When consolidating msg log I get: Object {length = 0, models = [0], _byId = {...}, more ...}
I also registered the parse function in the collection and it runs through the JSON file just fine ... any ideas on what might be wrong here? The length of the msg object should be 5..ie that how many times the parse function sings and (should) add the model to the collection.
Joel
source share