Proper way to sort a backbone.js collection on the fly

前端 未结 6 1246
孤独总比滥情好
孤独总比滥情好 2021-01-30 02:31

I can successfully do this:

App.SomeCollection = Backbone.Collection.extend({
  comparator: function( collection ){
    return( collection.get( \'lastName\' ) );         


        
6条回答
  •  忘掉有多难
    2021-01-30 02:54

    Looking at the source code, it seems there's a simple way to do it, setting comparator to string instead of function. This works, given Backbone.Collection mycollection:

            mycollection.comparator = key;
            mycollection.sort();
    

提交回复
热议问题