You can implement more logic in the comparator so that you can abstract away from some sorting logic:
var Collection = Backbone.Collection.extend({
model: myModel,
order: 'name'
comparator: function(model) {
if (this.order === 'name') {
return model.get('name');
} else {
return model.get('date');
}
}
});
Then, to change the sort order:
myCollection.order = 'date';
myCollection.sort();
This will call the comparator function and sort it that way.
:
this.listenTo(myCollection,'sort',this.render);
, , , , .