Can Backbone render a collection in reverse order?

后端 未结 8 1803
猫巷女王i
猫巷女王i 2021-02-09 04:19

I\'m using a Signalr hub to subscribe to events on the server. What an event is dispatched to a hub, its successfully adding the item to a Marionette CollectionView. This, in

8条回答
  •  没有蜡笔的小新
    2021-02-09 04:36

    Backbone automatically keeps Collections in sorted order. If you want to use a non-default sort, define a comparator() function on your Collection and it will use that instead. The comparator can take either one or two arguments, see the Backbone documentation for details.

    You can then render your collection in an .each() loop, and it will come out in the correct order. Adding new items to the view in sorted order is up to you, though.

提交回复
热议问题