2
我正在做一些html5/jquery拖放功能来重新排序一组DOM元素。我现在想要更改与这些DOM元素对应的对象数组,但我不太确定如何去做。这里的JavaScript:更改数组的顺序以匹配一组DOM元素的顺序
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
}