vue js 表格选中多条数据批量上移下移

批量上移

 //选中行数据
  let arrChecked = this.tableDataChecked;
  //表格数据
  let arr = this.tableData;
  //正序遍历,保证移动完成的数据在下一次循环时位置不会再变动
  a: for (let indexChecked = 0; indexChecked < arrChecked.length; indexChecked++) {
          b: for (let index = 0; index < arr.length; index++) {
          //选中数据定位到其在总数据中的位置时开始上移
            if (arrChecked[index1] === arr[index2]) {
            //选中数据与总数据索引相同时,说明已经上移到最上层,结束这层
            //循环
              if (index1 === index2) {
                break b;
              }
              //上移一位到达上一条数据的上方
              arr.splice(index2 - 1, 0, arr[index2]);
              //删除原数据
              arr.splice(index2 + 1, 1);
              //上移完成结束内存循环,开始移动下一条选中数据
              break b;
            }
          }
        }

批量下移

 let arrChecked = this.tableDataChecked;
 let arr =  this.tableData;
     a:for(let index1 = arrChecked.length - 1; index1 >= 0 ; index1--) {
         b:for(let index2 =  arr.length - 1; index2 >= 0; index2--) {
             if (arrChecked[index1] === arr[index2]) {
             //选中数据索引+表格数组长度-选中数组长度=选中数据索引,代表以及下移到最底部,结束下移
                 if(index1 + arr.length - arrChecked.length === index2){
                     break a;
                 }
                 arr.splice(index2 + 2, 0, arr[index2]);
                 arr.splice(index2, 1);
                 break b;
             }
         }
     }
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值