I have a Backbone.js app with marionette plugin. There's a collection which renders with a CompositeView (and ItemViews) and I need to sort it in the following way:
- User can rearrange rendered ItemViews (using jQuery sortable plugin) and this user preference gets saved in a cookie in a form of array of model IDs
- On each reload, I want to sort the fetched collection to be in the same order as this aforementioned array of user preference order.
I tried to sort collection.models array manually in the onRender hook and then re-rendering it, but this kind of collection manipulation just "feels wrong" (and causes an endless render loop).
Is there some kind of a more elegant solution to sort a collection to have models in the same order as model IDs defined in some other array?