I'm trying to get this to work but I struggle with it. My Collection ends up empty when I check the success
callback on fetch
. It doesn't give me any clear errors thou during parse
. Here's 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 I console log msg
I get:
Object { length=0, models=[0], _byId={...}, more...}
I've also logged the parse
function in the collection and it runs thru the JSON file just fine...any ideas on what could be wrong here? The length of the msg
object should be 5..i.e. that's how many times the parse
function loops and (should) add a model to the collection.