kornelski / slip

Slip.js — UI library for manipulating lists via swipe and drag gestures
BSD 2-Clause "Simplified" License
2.44k stars 213 forks source link

Get order #85

Closed RemyyB closed 7 years ago

RemyyB commented 7 years ago

Hi, I'm using this plugin, but now I'd like to get the order of all the targets. I really don't know how to do this. In the slip:reorder and then spliceIndex I saw it, but I really don't know how to use this.

Thanks!

kornelski commented 7 years ago

I'm assuming your items are originally stored in some array.

var originalIndex = event.detail.originalIndex;
var spliceIndex = event.detail.spliceIndex
var movedItem = yourArray[originalIndex];
yourArray.splice(originalIndex, 1); // Remove item from the previous position
yourArray.splice(spliceIndex, 0, movedItem); // Insert item in the new position
RemyyB commented 7 years ago

Question, what's the variable yourArray (sorry, I'm a Javascript noob)

kornelski commented 7 years ago

substitute it for the array you use to store the items you're reordering.