我正在做一些 html5 / jquery 拖放功能来重新排序一组 DOM 元素。我现在想更改与这些 DOM 元素相对应的对象数组,但我不太确定该怎么做。这是javascript:
var draggedIndex = $('.segmentListItem').index($(draggedItem));
var targetIndex = $('.segmentListItem').index($(this));
var playlist = jwplayer().getPlaylist(); //MH - the array for which I want to change the order
if (draggedIndex > targetIndex){
$(draggedItem).insertBefore($(this));
//MH - need to move the playlist item at the index of the dragged item before index the target item as well
} else {
$(draggedItem).insertAfter($(this));
//MH - need to move the playlist item at the index of the dragged item before index the target item as well
}