Created
December 10, 2011 07:45
-
-
Save rmw/1454792 to your computer and use it in GitHub Desktop.
Backbone.js secondary sort order with collection comparator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Collections.Notes = Backbone.Collection.extend({ | |
model: Note, | |
url: '/notes.json', | |
comparator : function(note) { | |
//ordering by status (alphabetically asc) and id (numeric desc) | |
var stat = note.get('status'); | |
var note_id = note.get('id'); | |
var sort_order = (stat.charCodeAt(0) * 100000) - note_id; | |
return sort_order; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a better way to do this?