Backbone.js collection comparator sort by multiple fields?

@amchang87’s answer definitely works, but another that I found worked is simply returning an array of the sortable fields:

this.col = Backbone.Collection.extend({
    model: M,
    comparator: function(item) {
      return [item.get("level"), item.get("title")]
    }
});

I haven’t tested this in multiple browsers yet as I think it relies on JS’ behavior in sort order for arrays (based on their contents). It definitely works in WebKit.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)