Related Questions -
How can I move a model within a collection?
I have a Backbone collection, visually represented in a list. This list is drag/droppable. Any item can be moved to an arbitrary position in the collection (ie - not a sort). I've seen some examples that use the collection's native remove/add to put the model in the right place. However, Backbone internally calls set when models are added, which then calls a bunch of methods related to events and sorts it at the end. Is there any downside to just splicing the model to the correct position?
Remove/Add: See examples in first linked question.
Splice: Second example
Function I'm currently using:
moveTo: function(oldIndex, newIndex){
oldIndex = oldIndex instanceof Backbone.Model ? this.at(oldIndex) : oldIndex;
var spliced = this.models.splice(oldIndex, 1);
this.models.splice(newIndex, 0, spliced[0]);
this.trigger("move",[oldIndex,newIndex]);
},