• js 实现端口列表话


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    function compareTwo(jsonDate,key,listValue){
        var arrPorts = listValue.split('/');
        var prevValue = jsonDate.date.split('/');
        var prevFirst = prevValue[0].substring(0,prevValue[0].length-1);
        var arrPortsFirst = arrPorts[0].substring(0,arrPorts[0].length-1);
        if(parseInt(key) == parseInt(jsonDate.index)+1 && prevFirst == arrPortsFirst && prevValue[1] == arrPorts[1] ){
            return true;
        }
        return false;
    }
    
    function jsonLength(ports){
        var length = 0;
        for(var key in ports){
            length++;
        }
        return length;
    }
    
    /*获取字符串*/
    function getPortStr(portList){
        var prevDate = {index: '',date:''};
        var length = 0;
        var equTmpStr = '';
        var tmpStr = '';
        var tmpLength = '';
        var preStatus = false;
        var length = jsonLength(portList);
        alert("length:"+length);
        var ingStr = '';
        for(var key in portList){
            tmpLength++;
            var arrPorts = portList[key].split('/');
            if('' != prevDate.index){
                var comValue = compareTwo(prevDate,key,portList[key]);
                if(comValue){ //如果两个数是同类型的
                    //把现在的连接上以前用-
                    equTmpStr = prevDate.date+'-'+arrPorts[2];    
                    if(length == tmpLength){
                        ingStr += equTmpStr+',';
                        equTmpStr = '';
                    }
                    prevDate.index = key;
                    continue;
                }else{
                    //如果是不同类型的,需要先存起来
    
                    alert("key:"+key+" comValue:"+comValue+" equTmpStr: "+equTmpStr);
                    if('' != equTmpStr){
                        ingStr += equTmpStr+',';
                        equTmpStr = '';
                    }else{
                        ingStr += prevDate.date+',';
                    }
                    
                    if(length == tmpLength){
                            ingStr += portList[key]+',';
                    }
                }
            }
            prevDate.index = key;
            prevDate.date = portList[key];
        }
        ingStr = ingStr.substring(0,ingStr.length-1);
        return ingStr;    
    }
    
    /*整理字符串和命令行显示一致*/
    function getStrCollation(portList){
        var strPort = getPortStr(portList);
        alert("strPort:"+strPort);
        var arrPort = strPort.split(',');
        var arrTmp = [];
        var prevStrPortPartFirst = '';
        var prevStrPort = '';
        var exportStr = '';
        var j=0;
        for(var i=0;i<arrPort.length;i++){
            var arrPortPart = arrPort[i].split('/');
            var strPortPartFirst = arrPortPart[0].substring(0,arrPortPart[0].length-1);
            if(i){
                if(prevStrPortPartFirst == strPortPartFirst){
                    arrTmp[j] = arrPort[i].substring(strPortPartFirst.length);
                    j++;
                    if(i == arrPort.length-1){
                        exportStr += arrTmp.join(',');
                    }
                    continue;
                }else{
                    if(arrTmp.length){
                        exportStr += arrTmp.join(',')+' ';
                        arrTmp = [];
                        j = 0;
                    }
                    if(i == arrPort.length-1){
                        exportStr += arrPort[i];
                    }
                }
                
            }
            arrTmp.push(arrPort[i]);
            j++;
            prevStrPortPartFirst = strPortPartFirst;
        }
        return exportStr;
    }
    
    
    
    /*使用这个函数的前提是json中的数据按照从小到大的顺序排好*/
    function compareList(listSrc,listDes){
        var srcLength = jsonLength(listSrc);
        var desLength = jsonLength(listDes);
        
        if(srcLength != desLength){
            return false;
        }else{
            for(var key in listSrc){
                if(listSrc[key] != listDes[key]){
                    return false;
                }
            }
        }
        return true;
        
    }
        
    window.onload = function(){
        var portList = {'1': 'gigaethernet1/1/1','2':'gigaethernet1/2/7','3':'gigaethernet1/2/3','7':'fst1/5/1','8':'fst1/5/2','10':'fst1/6/2','11':'fst1/6/3','12':'fst1/6/4','16':'fst1/9/4','18':'fst1/10/4'};
        var portListTset = {'1': 'gigaethernet1/1/1','2':'gigaethernet3/1/7','3':'gigaethernet3/1/3','7':'fst1/5/1','8':'fst1/5/2'};
        var arrPort = ['gigaethernet1/1/1','gigaethernet1/1/2'];
        var str = 'abcdefg';
            //alert(str.substring(2));
        alert(getStrCollation(portList));
    };
    
    
    </script>
    </head>
    
    <body>
    </body>
    </html>
  • 相关阅读:
    boost-1.53源代码编译
    Hive分析窗体函数之NTILE,ROW_NUMBER,RANK和DENSE_RANK
    外接圆、内切圆半径公式及相应关系知识点总结
    最小生成树之Prim算法
    JavaScript实现简单图片滚动 --9张图告诉你,C罗欲哭无泪
    Scala入门到精通——第二十七节 Scala操纵XML
    第二十一篇:基​于​W​D​M​模​型​的​A​V​S​t​r​e​a​m​驱​动​架​构​研​究
    oracle表空间查询维护命令大全之中的一个(数据表空间)史上最全
    项目流程管理&amp;&amp;架构总结
    AIX常用命令略记
  • 原文地址:https://www.cnblogs.com/moon-yyl/p/8945775.html
Copyright © 2020-2023  润新知