Reputation: 17
From reading the documentation, it looks as if passing an array of models into a collection initializer should populate the collections models attribute with the supplied array. However, when I try, I end up with an empty collection. No errors, no indication of why it fails, it simply doesn't do anything? I've verified that my original fetch returns data and that my filter works correctly and returns an array - from there, everything goes south.
I'm trying to do something similar to the following example:
var files = new Backbone.Collection();
files.fetch({
success: function(collection){
var filtered = collection.where({ type: 'Software' });
var filteredCollection = new Backbone.Collection({ models: filtered });
}
})
When I run this, I get a filteredCollection with an empty models array. Someone mind pointing out the bonehead mistake I'm making? TIA!
Upvotes: 0
Views: 48
Reputation: 1799
To create the instance of Backbone Collection you should pass just an array as single argument.
var files = new Backbone.Collection();
files.fetch({
success: function(collection){
var filtered = collection.where({ type: 'Software' });
var filteredCollection = new Backbone.Collection(filtered);
}
});
Upvotes: 1