I am trying to add a dynamic sort by to my collection using backbone.js.
At initialization the collection has the default sorting and the view is rendered. I made a button to test how to change the sorting. It calls the following function:
app.productList.comparator = function(product) {
return parseFloat(product.get("price"));
};
app.productList.sort();
If I understand correctly the Collection should now be sorted but the view still needs to be refreshed. I read in the documentation and in this topic to listen for the sort
event
window.ProductCollection = Backbone.Collection.extend({
model:Product,
localStorage: new Backbone.LocalStorage("ProductCollection"),
events:{
"sort":"test"
},
test:function(){
alert('test');
}
});
For testing purposes I added a simple alert but this is not displayed. So it seems the sort event was not triggered.
Any ideas what I'm doing wrong here?