• js list数据 转 树状 层级 JSON,递归生成树状 层级 JSON


    <!DOCTYPE html>
    <html>
    <head>
    <script>
    var data=[
    {"id":"aaa","parentId":"account","spType":0,"layerId":0,"seqId":1,"name":"阿萨德发多少","deleted":"0"},
    {"id":"account","parentId":"","spType":0,"layerId":0,"seqId":50,"name":"账户","deleted":"0"},
    {"id":"bbb","parentId":"account","spType":0,"layerId":0,"seqId":2,"name":"阿萨德发多少","deleted":"0"},
    {"id":"ccc","parentId":"account","spType":0,"layerId":0,"seqId":3,"name":"a啊都是发","deleted":"0"},
    {"id":"ddd","parentId":"dispatch","spType":0,"layerId":0,"seqId":1,"name":"大夫","deleted":"0"},
    {"id":"dispatch","parentId":"","spType":0,"layerId":0,"seqId":2,"name":"通知公告","deleted":"0"},
    {"id":"eee","parentId":"dispatch","spType":0,"layerId":0,"seqId":2,"name":";卡萨丁","deleted":"0"},
    {"id":"fff","parentId":"gridding","spType":0,"layerId":0,"seqId":1,"name":"拉收到了","deleted":"0"},
    {"id":"gridding","parentId":"","spType":0,"layerId":0,"seqId":1,"name":"网格化管理","deleted":"0"},
    {"id":"portals","parentId":"","spType":0,"layerId":0,"seqId":3,"name":"综合信息门户管理","deleted":"0"}
    ];
    
       var getJsonTree=function(data,parentId){
        	var itemArr=[];
    		for(var i=0;i<data.length;i++){	
    			var node=data[i];
    			//data.splice(i, 1)
    			 if(node.parentId==parentId ){	
    				var newNode={id:node.id,title:node.name,nodes:getJsonTree(data,node.id)};
    				itemArr.push(newNode);				 
    			 }
    		}
    		return itemArr;
        }
    	
    	console.log(getJsonTree(data,''));
    	
    	
    </script>
    </head>
    
    <body>
    
    
    </body>
    </html>
    

      

  • 相关阅读:
    verilog编码规范
    verilog代码 想法验证---与寄存器输出有关
    MMCM与PLL
    Vivado约束文件(XDC)的探究(2)
    Vivado约束文件(XDC)的探究(1)
    VGA图像显示组成模块分析
    关于Quad PLL /CPLL参考时钟的选择
    GTX的生成(包括COMMON)
    SD-SDI播出系统---使用GTX TX产生恢复时钟
    DRP端口描述
  • 原文地址:https://www.cnblogs.com/pangguoming/p/7373991.html
Copyright © 2020-2023  润新知