How do I change the sort order of a backbone collection after it has already been initialized?
Tried this: Doesn’t work
collection.comparator = function () {
// new function
}
collectionObject.sort()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think you are defining the comparator correctly. If you define a comparator, objects will be inserted into the collection in the right order.
Here is an example you can just run through firebug on a site with backbone loaded:
Notice how the comparator returns the value stored in the page attribute of each chapter. Backbone’s collection sorting acts like a sortBy which uses strings or ints, and doesnt follow a traditional -1,0,1 comparator approach.