Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone insert at position and shift models

Is there a simple way to insert models at a position of a collection and shift all models including the one at the specified index back, so basically 'slipping' a model into a collection at a position?

like image 754
el_pup_le Avatar asked Jan 31 '26 01:01

el_pup_le


1 Answers

Inserting into collection at the specified index could be performed with the method .add() with passing option {at: index}:

myCollection.add(myModel, {at: 14});

Also for the second part of your question there are corresponding methods such as .slice().

I bet you could find the most appropriate one in the documentation.

like image 136
Eugene Naydenov Avatar answered Feb 01 '26 14:02

Eugene Naydenov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!