I have a basic collection:
myCollection = Backbone.Collection.extend({
model: myModel
url: '/theurl',
initialize: function(){
this.fetch();
})
})
Upon initialization, the collection receives items ordered by date. I would like to be able to dynamically change the collection order using a different model attribute (name, rating, etc.).
In the collection-related view, I tried to associate the click event with a callback as follows:
reorderByName: function(){
myCollection.comparator = function(item){
return item.get('name');
});
this.render();
})
Unfortunately this does not work. Any suggestions on how I can do this?
Thank.
source
share