美文网首页
怎么把数组中的某一项移动到第一项

怎么把数组中的某一项移动到第一项

作者: _信仰zmh | 来源:发表于2018-04-04 16:26 被阅读36次

    这个我暂时还没有更好的方法,目前我的想法是,找到要删除的项的索引,取到这一项,然后删除这一项,最后再数组最前方添加这一项

    • for 循环,得到index
    • 复制obj删除第index项,使用splice方法
    • 将复制的obj,放到数组最前方,使用unshift方法。

    这是我本地写的测试:

    var lastLoginTenantId = 3;
    var dataset = [{"tenantID":0,'s':"dsf"},{"tenantID":1,'s':"dsf"},
                   {"tenantID":2,'s':"dsf"},{"tenantID":3,'s':"dsf"},
                   {"tenantID":4,'s':"dsf"},{"tenantID":5,'s':"dsf"}];
    
    var obj = {};
    for(var i = 0; i < dataset.length; i++){
       if(dataset[i].tenantID == lastLoginTenantId){
              //var index = i;
             obj =dataset[i];
             dataset.splice(i,1);// 第i位删除1项
             dataset.unshift(obj)
         }
    }
    
    测试demo.png

    是不是很麻烦,哈哈,要是有更好的方法,请email我:zhouminghangqdgcs@163.com

    项目中的场景

    这里暂时不写了,就是记录一下最后的id,到localStorage里面。

    <li>
            <label class="aw-label-icon pull-left"><i class="fa fa-user"></i></label>
             <input id="username" name="username" tabindex="1"
                     type="text" class="form-control aw-login-input"
                     placeholder="用户名"
                     value="<%=encoder.encodeForHTMLAttribute(username)%>" 
                     style="box-shadow:none" >
    </li>
    
    localStorage.setItem("LoginUserId_"+loginUserId, id);
    

    点击登陆按钮,保存最后的租户id到localStorage

    loginClick = function (tId) {
        var loginUserId = $("#username").val().trim();
        if (self.parent.document.loginType != "popup") {
            if ($("#p_username").val().indexOf("\"") >= 0) {
                alert("用户名不能含有非法字符\"!");
                return false;
            }
            //提交前,增加逻辑判断
            toastr.options = {
                "positionClass": "toast-top-center"
            };
            var userId = $("#username").val();
            var password = $("#p_password").val();
            if(null==userId || ""==userId.trim()){
                toastr.error("请输入登陆账号");
                return;
            }
            if(null==password || ""==password.trim()){
                toastr.error("请输入登陆密码");
                return;
            }
            //var tenantselect = $("#tenantID");
            //var tenantID = tenantselect.val();
            var tenantID = tId?tId:"";
            $("#tenantID").val(tenantID);
            //检测用户账号密码是否相同
            var checkParam = {
                service: "BC23",
                method: "checkPWD",
                eiinfo: '{attr:{"service":"BC23","method":"checkPWD","user":"'+userId+'","password":"'+ password +'"},blocks:{}}'
            };
            var check_status = 0;
            $.ajax(
                {
                    type: "POST",
                    async: false,
                    url: CONTEXT_PATH + "/EiService",
                    data: checkParam,
                    dataType: "json",
                    success: function (msg) {
                        var status = msg['status'];
                        check_status = status;
                        if (status<0) {
                            toastr.options = {
                                "positionClass": "toast-top-center"
                            };
                            if(-98==status){
                                window.location.href = "./DispatchAction.do?efFormEname=ES23&userId="+userId;
                                return false;
                            }
                            if(-99==status){
                                if(null==tenantID || ""==tenantID){
                                    toastr.info(msg['msg']);
                                    getTenantList();
                                    $("#tenant-model-box").show();
                                    $("#closeModel").click(function(){
                                        $("#searchTenant").val("");
                                        $("#divSelectLi").empty();
                                        $("#tenant-model-box").hide();
                                    });
                                    var selectIndex = -1;
                                    $("#searchTenant").focus();
                                    //$(document).keydown(function(event){
                                    //$(document).keyup(function(event){
                                    $("#searchTenant").keyup(function(event){
                                        var target = event.target;
                                        var selectUi = document.getElementById("divSelectLi");
                                        //取得li的元素
                                        var selectList = document.getElementsByClassName("search-li-tenant");
                                        for(var i=0;i<selectList.length;i++){
                                            selectList[i].style.borderLeftColor = "transparent";
                                        }
                                        var keyCode = event.keyCode;
                                            switch (keyCode) {
                                                //move up
                                                case 38:
                                                    if (selectIndex <= 0) {
                                                        selectIndex = -1;
                                                    } else {
                                                        selectIndex--;
                                                    }
                                                    break;
                                                //move down
                                                case 40:
                                                    if (selectIndex < 0 || selectIndex == selectList.length - 1) {
                                                        selectIndex = 0;
                                                    } else {
                                                        selectIndex++;
                                                    }
                                                    break;
                                                //enter
                                                case 13:
                                                    event.preventDefault(); // 兼容标准浏览器
                                                    window.event.returnValue = false; // 兼容IE6~8
                                                    if (selectIndex != -1) {
                                                        if($("#divSelectLi li").length > 0){
                                                            $("#divSelectLi li").removeClass("gr");
                                                            $("#divSelectLi li:nth-child(" + (selectIndex + 1) + ")").addClass("gr");
                                                            var id = $("#divSelectLi .search-li-tenant .selectTenantIdLi")[selectIndex].innerHTML;
                                                            var loading = '<img style="width: 16px;height: 16px;display: inline-block;margin-left: 16px;" src="data:image/gif;base64,R0lGODlhIAAgALMAAP///7Ozs/v7+9bW1uHh4fLy8rq6uoGBgTQ0NAEBARsbG8TExJeXl/39/VRUVAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFBQAAACwAAAAAIAAgAAAE5xDISSlLrOrNp0pKNRCdFhxVolJLEJQUoSgOpSYT4RowNSsvyW1icA16k8MMMRkCBjskBTFDAZyuAEkqCfxIQ2hgQRFvAQEEIjNxVDW6XNE4YagRjuBCwe60smQUDnd4Rz1ZAQZnFAGDd0hihh12CEE9kjAEVlycXIg7BAsMB6SlnJ87paqbSKiKoqusnbMdmDC2tXQlkUhziYtyWTxIfy6BE8WJt5YEvpJivxNaGmLHT0VnOgGYf0dZXS7APdpB309RnHOG5gDqXGLDaC457D1zZ/V/nmOM82XiHQjYKhKP1oZmADdEAAAh+QQFBQAAACwAAAAAGAAXAAAEchDISasKNeuJFKoHs4mUYlJIkmjIV54Soypsa0wmLSnqoTEtBw52mG0AjhYpBxioEqRNy8V0qFzNw+GGwlJki4lBqx1IBgjMkRIghwjrzcDti2/Gh7D9qN774wQGAYOEfwCChIV/gYmDho+QkZKTR3p7EQAh+QQFBQAAACwBAAAAHQAOAAAEchDISWdANesNHHJZwE2DUSEo5SjKKB2HOKGYFLD1CB/DnEoIlkti2PlyuKGEATMBaAACSyGbEDYD4zN1YIEmh0SCQQgYehNmTNNaKsQJXmBuuEYPi9ECAU/UFnNzeUp9VBQEBoFOLmFxWHNoQw6RWEocEQAh+QQFBQAAACwHAAAAGQARAAAEaRDICdZZNOvNDsvfBhBDdpwZgohBgE3nQaki0AYEjEqOGmqDlkEnAzBUjhrA0Co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aCcT0CUBTgaTg5nTCu9GKiDEMPJg5YBBOpwlnVzLwtqyKnZagZWahoMB2M3GgsHSRsRACH5BAUFAAAALAEACAARABgAAARcMKR0gL34npkUyyCAcAmyhBijkGi2UW02VHFt33iu7yiDIDaD4/erEYGDlu/nuBAOJ9Dvc2EcDgFAYIuaXS3bbOh6MIC5IAP5Eh5fk2exC4tpgwZyiyFgvhEMBBEAIfkEBQUAAAAsAAACAA4AHQAABHMQyAnYoViSlFDGXBJ808Ep5KRwV8qEg+pRCOeoioKMwJK0Ekcu54h9AoghKgXIMZgAApQZcCCu2Ax2O6NUud2pmJcyHA4L0uDM/ljYDCnGfGakJQE5YH0wUBYBAUYfBIFkHwaBgxkDgX5lgXpHAXcpBIsRADs="/><span style="font-size: 12px;margin-left: 5px;color: gray;">正在登录中,请等待...</span>';
                                                            $("#divSelectLi li:nth-child(" + (selectIndex + 1) + ")").children(".addLoding").empty().append(loading);
                                                            localStorage.setItem("LoginUserId_"+loginUserId, id);
                                                            loginClick(id);
                                                        }
    
                                                        //selectIndex = -1;
                                                    }
                                                    break;
                                                default:
                                                        setTimeout(function(){
                                                            $("#divSelectLi").empty();
                                                            if ($("#divSelectLi li").length == 0) {
                                                                getTenantList();
                                                            }
                                                        },500);
                                                    break;
                                            }
                                        if(selectIndex < 7){
                                            $(".search-result")[0].scrollTop = 0;
                                        }else if(selectIndex < $("#divSelectLi li").length){
                                            $(".search-result")[0].scrollTop = (selectIndex-7)*36;
                                        }else{
                                            selectIndex = -1;
                                            $(".search-result")[0].scrollTop = 0;
                                        }
                                        if(selectIndex>=0){
                                            $("#divSelectLi li:nth-child("+(selectIndex+1)+")").css("borderLeftColor","#ff9900");
                                        }
                                    });
    
                                    $("#searchTenant").blur(function(){
                                        $("#divSelectLi li").click(function(){
                                            $("#divSelectLi li").removeClass("gr");
                                            var loading = '<img style="width: 16px;height: 16px;display: inline-block;margin-left: 16px;" src="data:image/gif;base64,R0lGODlhIAAgALMAAP///7Ozs/v7+9bW1u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AACAA4AHQAABHMQyAnYoViSlFDGXBJ808Ep5KRwV8qEg+pRCOeoioKMwJK0Ekcu54h9AoghKgXIMZgAApQZcCCu2Ax2O6NUud2pmJcyHA4L0uDM/ljYDCnGfGakJQE5YH0wUBYBAUYfBIFkHwaBgxkDgX5lgXpHAXcpBIsRADs="/><span style="font-size: 12px;margin-left: 5px;color: gray;">正在登录中,请等待...</span>';
                                            $(this).addClass("gr");
                                            var id = $(this).children(".selectTenantIdLi").html();
                                            $(this).children(".addLoding").empty().append(loading);
                                            localStorage.setItem("LoginUserId_"+loginUserId, id);
                                            loginClick(id);
                                        });
                                    });
    
    
    
                                }else{
                                    check_status = 1;
                                }
                            }else{
                                toastr.error(msg['msg']);
                            }
                        }
                    },
                    error: function (xmlR, status, e) {
                        check_status = -1;
                        toastr.error("登陆异常");
                    }
                });
    
            if(check_status<0){
                return;
            }
            $("#p_username").val(userId);
            document.getElementById('ef-LoginForm').submit();
        }
        else {
            //$$LOGIN$$:"true" 支持silverlight登录,用于处理session
    
            var cookieStr = window.getTopWnd().document.getElementById("COOKIE").value;
            var jsonEi = "{}";
            var reqParams = {
                service: "EP50",
                method: "initLoad",
                eiinfo: jsonEi,
                $$LOGIN$$: "true",
                $$keepSession$$: "true",
                p_username: ef.get("p_username").value,
                p_password: ef.get("p_password").value,
                RELOGIN: ef.get("RELOGIN").value,
                COOKIE: cookieStr
            };
            if ($('#p_captcha').length > 0) {//开启了验证码功能
                reqParams = {
                    service: "EP50",
                    method: "initLoad",
                    eiinfo: jsonEi,
                    $$LOGIN$$: "true",
                    $$keepSession$$: "true",
                    p_username: ef.get("p_username").value,
                    p_password: ef.get("p_password").value,
                    p_captcha: ef.get("p_captcha").value,
                    RELOGIN: ef.get("RELOGIN").value,
                    COOKIE: cookieStr
                };
            }
            $.ajax(
                {
                    type: "POST",
                    async: false,
                    url: CONTEXT_PATH + "/EiService",
                    //data:     "service=" + sService + "&method=" + sMethod + "&eiinfo=" + jsonEi,
                    data: reqParams,
                    dataType: "json",
                    success: function (msg) {
                        ajaxEi = Json2EiInfo.prototype.parseJsonObject(msg);
    
                        if (ajaxEi.status == "-1") {
                            if (isAvailable(msg.msg)) {
                                $("#loginTip").css("color", "red").text("*" + msg.msg);
                            }
                            else {
                                $("#loginTip").css("color", "red").text("*" + "登录失败,用户名不能为空");
                            }
    
                        }
                        else {
                            parent.$.fn.colorbox.close();
                            var topWnd = getTopWnd();
                            if (isAvailable(topWnd) && isAvailable(topWnd.lastActivity)) {
                                topWnd.lastActivity = new Date().getTime();
                            }
    
    
    //                          self.parent.window.lastActivity = new Date().getTime();
                        }
    
                        //用于session恢复.当第一次session失效重登录后,如果当前页面没有刷新而session再次失效,那再页面中保存的保存的sessionId还是原来的值,所以需要更新sessionId
                        var platSessionId = ajaxEi.get("platSessionId");
                        if (platSessionId != null && platSessionId.trim() != "")
                            window.getTopWnd().document.getElementById("COOKIE").value = platSessionId;
                    },
                    error: function (xmlR, status, e) {
                        //20080806增加 当Ajax调用失败是 将ajaxEi置空(hubing)
                        ajaxEi = null;
                        $("#loginTip").css("color", "red").text("*" + "AJAX请求异常,登录失败!");
                    }
                });
        } //else
    }
    
    

    从本地localStorage获取该用户,最后的登陆租户id,将最后登陆的放在最前方即可。

    function getTenantList(){
        var loginUserId = $("#username").val().trim();
        var tName = $("#searchTenant").val().trim()? $("#searchTenant").val().trim():"";
        var lastLoginTenantId = localStorage.getItem("LoginUserId_"+loginUserId);
    
        var param1 = {
            service: "BC23",
            method: "getTenantList",
            eiinfo: '{attr:{"service":"BC23","method":"getTenantList","limit":"-1","offset":"0","showCount":"true","tenantName":"'+tName+'"},blocks:{}}'
        };
        $.ajax(
            {
                type: "POST",
                async: false,
                url: CONTEXT_PATH + "/EiService",
                data: param1,
                dataType: "json",
                success: function (result) {
                    var resultStatus = result.status;
                    if(resultStatus=='0') {
                        var allCount = result.attr.count;
                        $("#showTenantListCount").html(allCount);
                        var dataset = result.attr.tenants;
                        if(dataset.length == '0'){
                            var  createLi =  '<h6 class="search-result-title" ng-if="cTenant.counts == 0" style="text-align: center;">'+
                                '<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTIyNzMzMTQ1ODQ1IiBjbGFzcz0iaWNvbiIgc3R5bGU9IiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9Ijk3MDciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMzIiIGhlaWdodD0iMzIiPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PC9zdHlsZT48L2RlZnM+PHBhdGggZD0iTTUxMiAwQzIyOS4yNDggMCAwIDIyOS4yNDggMCA1MTJjMCAyODIuNzg0IDIyOS4yNDggNTEyIDUxMiA1MTIgMjgyLjc4NCAwIDUxMi0yMjkuMjE2IDUxMi01MTJDMTAyNCAyMjkuMjQ4IDc5NC43ODQgMCA1MTIgMHogbS01MS4xODQgMjE3LjZjMC0yOC4yNTYgMjIuOTQ0LTUxLjE4NCA1MS4xODQtNTEuMTg0IDI4LjI4OCAwIDUxLjIxNiAyMi45NDQgNTEuMjE2IDUxLjE4NHY0MDkuNjMyYzAgMjguMjU2LTIyLjk0NCA1MS4xODQtNTEuMjE2IDUxLjE4NC0yOC4yNTYgMC01MS4xODQtMjIuOTQ0LTUxLjE4NC01MS4xODRWMjE3LjZ6TTUxMiA4NzMuNmMtMzUuMzQ0IDAtNjQtMjguNjI0LTY0LTY0IDAtMzUuMzQ0IDI4LjY1Ni02NCA2NC02NCAzNS4zNzYgMCA2NCAyOC42NTYgNjQgNjQgMCAzNS4zNzYtMjguNjI0IDY0LTY0IDY0eiIgZmlsbD0iIzQzOEVCOSIgcC1pZD0iOTcwOCI+PC9wYXRoPjwvc3ZnPg==" style="width: 24px;height: 27px;margin-top: -4px;margin-right: -4px;"/>'+
                                '<span style="font-size:20px;margin-left:10px;">没有查询到符合条件的记录</span>'+
                                '</h6>';
                            $("#divSelectLi").append(createLi);
                        }
    
                        if(lastLoginTenantId){
                            var obj = {};
                            for(var i = 0; i < dataset.length; i++){
                                if(dataset[i].tenantID == lastLoginTenantId){
                                    obj =dataset[i];
                                    dataset.splice(i,1);
                                    dataset.unshift(obj)
                                }
                            }
                        }
    
                        for (var i = 0; i < dataset.length; i++) {
                            if ('社会' == dataset[i].tenantGroupType) {
                                color = "#ef8c00";
                            }
                            if ('企业' == dataset[i].tenantGroupType) {
                                dataset[i].color = "#43a300";
                            }
                            if ('宝钢' == dataset[i].tenantGroupType) {
                                dataset[i].color = "#0043a3";
                            }
                            if ('欧冶' == dataset[i].tenantGroupType) {
                                dataset[i].color = "#e60012";
                            }
    
                            var createLi = '<li class="search-li-tenant">' +
                                '<i class="fa fa-user" style="color:#999;"></i>' +
                                '<span style="vertical-align: middle">' + dataset[i].tenantName + '</span> ' +
                                '<span class="selectTenantIdLi" style="display:none;">' + dataset[i].tenantID + '</span><span class="addLoding"></span>' +
                                '<b class="search-type showTitle" style="vertical-align: middle; max-width:100px;background:' + dataset[i].color + ';">' + dataset[i].tenantGroupType + '</b>' +
                                '</li>';
                            $("#divSelectLi").append(createLi);
                        }
                    }
                },
                error: function (xmlR, status, e) {
                    console.log(e);
                }
            });
    }
    

    相关文章

      网友评论

          本文标题:怎么把数组中的某一项移动到第一项

          本文链接:https://www.haomeiwen.com/subject/jpnkhftx.html