Get position in javascript drag & drop array

I have a sorted list and I want to get the position of the object that I dragged into my array. Therefore, I can pass it using ajax and save it in my db, but I cannot figure out how to do this with a for loop

Here is my code

 <script> $(document).ready(function () { var rootLimit = 8; $('ul.sortable').nestedSortable({ handle: 'a', items: 'li', listType: 'ul', maxLevels: '3', toleranceElement: '> a', update: function (event, ui) { list = $(this).nestedSortable('toHierarchy', { startDepthCount: 0 }); var page_id = ui.item.find('> a').attr('data-page-id'); console.log(list); for (var i = 0; i < list.length; i++) { var index = $(this).index(); console.log(index); } $.post( '/page/updatemenu/' + page_id, { list : list }, function (data) { } ); } }); }); </script> 

and here is my jsFiddle , thanks!

+4
source share
1 answer

in your update function,

 $(ui.item).index() 

gives you the position of your item;

0
source

All Articles