I have a simple function in backbone.js
that sorts items in a collection after selecting a menu item (here called "Sort by Price"):
setSort: (event)->
event.preventDefault()
event.stopPropagation()
$target = $(event.target)
switch $target.text()
when "Sort by Price"
@collection.comparator = (model)->
model.get("Price")
@collection.sort()
which is pretty straightforward -- it grabs the Price
attribute from the individual models in the collection, and then sorts them. This part works.
Now I want to take a different field, a Name
attribute (a string) and to run an arbitrary hash on it in order to simulate an arbitrary sort. How would I go about doing this?