I\'m quite new to Backbone so I am getting into some problems I can\'t quite figure out.
I have a Backbone collection with a bit over 100 items. I want to filter the
Backbone collections are automatically sorted by the order of insertion, unless you implement Collection#comparator
. The problem is that your filtering algorithm is not producing an ordered output.
If you need to maintain an ordered collection only when filtering by id, I would suggest implementing a separate method, because seach by id is far faster compared to search by arbitrary attributes:
filterById: function(idArray) {
return this.reset(_.map(idArray, function(id) { return this.get(id); }, this));
}
Usage:
collection.filterById(['1', '2', '146', '3', '4', '9', '26', '8', '96', '10', '11', '54',' 145', '273', '38']);