I'm attempting to learn Backbone.js and have run into a bit of a wall when it comes to sorting.
My model is a song, and it has the attributes 'title', 'minutes', 'seconds', and 'order'.
Right now, I simply add each song to my View by adding them as list elements to an unordered list. My function looks like this:
$('#oList', this.el).append("<li id = 'song' > Song Name: " + song.get('title') + " Minutes: " + song.get('minutes') + " Seconds" + song.get('seconds') + "</li>");
They are also added to a collection before being appended.
I want to be able to sort based on title (alphabetically) and song length (numerically, based on the total of minutes and seconds).
Is there any easy way to do this? I've read about the sort() function in Backbone, as well as the comparator, but I'm still not seeing what I am supposed to be doing. Mainly, how will all my elements be added back into my View? When I want to sort by title, do I have to clear the list in my HTML and somehow re-add each element?
Any direction is greatly appreciated.