Sorting things on the fly in Backbone.js
November 12, 2012 3:10 PM Subscribe
Question about sorting in the Backbone.js framework.
posted by steinsaltz to Computers & Internet (17 answers total)
I'm making a database of plants. The plants can either be sorted by common name, or Latin name. A radio button would let the user toggle between the two.
Backbone sorts collections of models using a function called Comparator. I can get Comparator to do the default when it boots up...a sort-by-English-name...but am having trouble making it toggle over to a new criteria.
After reading Stack Overflow
I gather this has something to do with Comparator being evaluated one time when you start up, and then not being willing to re-evaluate in certain situations. Then there's some other talk
about recent changes that have improved the "sort by" ability. But I am still having trouble figuring out the best way to use this.
Could anyone help give me an example of a simple way to make the comparator toggle between two different sort-bys? Any help much appreciated.