//上移
function moveUpObj(manaualList, node) {
let moveIndex = manaualList.indexOf(node.data);
if (moveIndex != manaualList.length - 1) {
let removeItem = manaualList.splice(moveIndex, 1)
manaualList.splice(moveIndex + 1, 0, removeItem[0])
}
}
//下移
function moveDownObj(manaualList, node) {
//先获取该节点在数组中的索引
let moveIndex = manaualList.indexOf(node.data);
//如果不是第一个元素,则用splice将该元素截取赋值给一个变量
if (moveIndex != 0) {
let removeItem = manaualList.splice(moveIndex, 1)
manaualList.splice(moveIndex - 1, 0, removeItem[0])
}
}
如何实现纯前端的上移下移操作
最新推荐文章于 2024-02-20 16:19:55 发布