Backbone/Underscore sortBy is not sorting collection

前端 未结 3 1440

I have a list of users (six to be exact) in a collection with \'firstname\', \'lastname\' properties. Doing a fetch, the comparator below sorts them by \'firstname\', and it wor

3条回答
  •  情歌与酒
    2021-02-04 15:57

    The sortBy function does not sort the objects in the current collection. It returns a sorted collection:

    
    var sortedCollection = this.collection.sortBy(function(user){
      return user.get("lastname").toLowerCase();
    });
    

    Now you can use sortedCollection and it will be sorted correctly.

提交回复
热议问题