The best way to sort a collection in a CompositeView

后端 未结 3 1018
旧巷少年郎
旧巷少年郎 2021-02-19 06:45

I am trying to sort a collection in a Marionette.CompositeView.
I have a collection which looks like this:

[
   {id: 1, name: \'bar\'},
           


        
3条回答
  •  失恋的感觉
    2021-02-19 07:34

    Can you declare the .comparator when you create the collection? from your code the .comparator exists only on local variable var collection inside onRender function. If defined correctly the collection must be automatically sorted and you do not need to call .sort after adding new model

    var Chapters = new Backbone.Collection({
        comparator = function(chapter) {
            return chapter.get("id");
        };
    });
    

提交回复
热议问题