jsは、配列パケットに従って、tableを動的に生成する(同じ項のマージ).

9904 ワード

  
<html>  
 <head>  
  <title> New Document title>  
  <script>  
  //xxbh:    ,bjbh:    ,xx:    
    var arrJson=[  
        {'xxbh':'1001','bjbh':'0801','xx':'  '},{'xxbh':'1001','bjbh':'0802','xx':'  '},  
        {'xxbh':'1003','bjbh':'0803','xx':'  '},{'xxbh':'1003','bjbh':'0804','xx':'  '},  
        {'xxbh':'1005','bjbh':'0701','xx':'  '},{'xxbh':'1002','bjbh':'0701','xx':'  '},  
        {'xxbh':'1005','bjbh':'0701','xx':'  '},{'xxbh':'1002','bjbh':'0801','xx':'  '},  
        {'xxbh':'1005','bjbh':'0802','xx':'  '},{'xxbh':'1002','bjbh':'0901','xx':'  '},  
        {'xxbh':'1003','bjbh':'0901','xx':'  '},{'xxbh':'1004','bjbh':'0901','xx':'  '},  
        {'xxbh':'1001','bjbh':'0901','xx':'  '},{'xxbh':'1006','bjbh':'0901','xx':'  '},  
        {'xxbh':'1005','bjbh':'0901','xx':'  '},{'xxbh':'1004','bjbh':'0901','xx':'  '},  
        {'xxbh':'1006','bjbh':'0901','xx':'  '},{'xxbh':'1004','bjbh':'0901','xx':'  '},  
        {'xxbh':'1002','bjbh':'0901','xx':'  '},{'xxbh':'1001','bjbh':'0901','xx':'  '}  
    ];  
    function creatMapByXxbh(arrJson){  
        var xxbhMap={};  
        var len = arrJson.length;  
        for(var i=0;iif(xxbhMap[arrJson[i].xxbh] == undefined){  
                var list = [];  
                list.push(arrJson[i]);  
                xxbhMap[arrJson[i].xxbh] = list;  
            }else{  
                xxbhMap[arrJson[i].xxbh].push(arrJson[i]);  
            }  

        }  
        var str="";  
        for(var xxbh in xxbhMap){  
            var stu = xxbhMap[xxbh];  
            alert(stu.length);  
            str+="";  
            for(var i = 0;i < stu.length;i++){  
                //document.write(xxbh + " "+stu[i].bjbh+" "+stu[i].xx +"
")
//document.write("
"+xxbh+"
")
if(i==0){ str+=""+stu[i].bjbh+""+stu[i].xx+""
; }else{ str+=""+stu[i].bjbh+""+stu[i].xx+""; } } str+=""+xxbh+" "+stu.length+" " } str+=" "; document.write(str) } script> head > <body> <button onclick='creatMapByXxbh(arrJson)'> button> body> html>