关于处理前端list相邻位置交换处理

俩个方法:

actomicOrderSort:主要提取出需要操作的俩个对象:orderState为操作状态(1,表示前移一位。2,表示后移一位),atomicorder需要操作的对象的当前排序。

changeAtomicOrder:将actomicOrderSort()方法中提取出的俩个需要操作的对象,将其从list中删除,然后重新push进去。

    /*原子排序*/
    function actomicOrderSort(orderState, atomicorder) {
        var nowAtomic = {};
        var willAtomic = {};
        for (var i = 0; i < atomicList.length; i++) {
            var atomic = atomicList[i];
            if (orderState == 1) {
                /*表示原子前移*/
                if (atomicorder - 1 < 1) {
                    layer.msg("已经是最前面的原子了!", {time: 1500});
                    return;
                }
                if (atomic.order == atomicorder - 1) {
                    willAtomic.order = atomic.order + 1;
                    willAtomic.name = atomic.name;
                    willAtomic.id = atomic.id;
                    willAtomic.content = atomic.content;
                    willAtomic.keyword = atomic.keyword;
                }
                if (atomic.order == atomicorder) {
                    nowAtomic.order = atomic.order - 1;
                    nowAtomic.name = atomic.name;
                    nowAtomic.id = atomic.id;
                    nowAtomic.content = atomic.content;
                    nowAtomic.keyword = atomic.keyword;
                }
            } else if (orderState == 2) {
                /*表示原子后移*/
                if (atomicorder + 1 > atomicList.length) {
                    layer.msg("已经是最后的原子了!", {time: 1500});
                    return;
                }
                if (atomic.order == atomicorder) {
                    nowAtomic.order = atomic.order + 1;
                    nowAtomic.name = atomic.name;
                    nowAtomic.id = atomic.id;
                    nowAtomic.content = atomic.content;
                    nowAtomic.keyword = atomic.keyword;
                }
                if (atomic.order == Number(atomicorder) + Number(1)) {
                    willAtomic.order = atomic.order - 1;
                    willAtomic.name = atomic.name;
                    willAtomic.id = atomic.id;
                    willAtomic.content = atomic.content;
                    willAtomic.keyword = atomic.keyword;
                }
            }
        }
        changeAtomicOrder(atomicList, nowAtomic, willAtomic);
        type = 1;
        actomicStr = JSON.stringify(atomicList);
        showAtomic();
    }

    function changeAtomicOrder(atomicList, nowAtomic, willAtomic) {
        for (var i = 0; i < atomicList.length; i++) {
            var atomicListElement = atomicList[i];
            if (atomicListElement.id == nowAtomic.id) {
                atomicList.splice(i, 1);
            }
        }
        atomicList.push(nowAtomic);
        for (var i = 0; i < atomicList.length; i++) {
            var atomicListElement = atomicList[i];
            if (atomicListElement.id == willAtomic.id) {
                atomicList.splice(i, 1);

            }
        }
        atomicList.push(willAtomic);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值