- 数组两项元素交换位置
const exchange = (dragIndex, hoverIndex) => {
arr[dragIndex] = arr.splice(hoverIndex, 1, arr[dragIndex])[0]
}
- 把数组里的某一项移动到某一位置(常见拖拽的时候drop函数里用)
const exchange = (dragIndex, dropIndex) => {
const copyLists = [...arr];
const dragData = copyLists.splice(dragIndex, 1);
const effticeDropIndex = dragIndex < dropIndex ? (dropIndex - 1) : dropIndex
copyLists.splice(effticeDropIndex, 0, dragData[0]);
}
网友评论