Backbone.js collection comparator sort by multiple fields?

后端 未结 5 1339
臣服心动
臣服心动 2020-12-14 06:11
  this.col = Backbone.Collection.extend({
    model: M,
    comparator: function(item) {
      return item.get(\"level\");
    }
  });

This above c

5条回答
  •  感情败类
    2020-12-14 06:40

    @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.

提交回复
热议问题