zoukankan      html  css  js  c++  java
  • json转树状菜单栏

    //生成树状json格式
    
     
    
    //a=>json数据源
    
    //idstr=>子Id关键字
    
    //pidStr=>父Id关键字
    
    //chindrenStr=>生成的chindrenStr字段
    
    function transData(a, idStr, pidStr, chindrenStr)
    
    {
    
    var r = [], hash = {},
    
    id = idStr,
    
    pid = pidStr,
    
    children = chindrenStr,
    
    i = 0,
    
    j = 0,
    
    len = a.length;
    
    for(; i < len; i++)
    
    {
    
    hash[a[i][id]] = a[i];
    
    }
    
    for(; j < len; j++){
    
    var aVal = a[j],
    
    hashVP = hash[aVal[pid]];
    
    if(hashVP){
    
    !hashVP[children] && (hashVP[children] = []);
    
    hashVP[children].push(aVal);
    
    }
    
    else{
    
    r.push(aVal); } } return r;
    
    }
  • 相关阅读:
    Python下载安装
    批量修改样式及全选反选
    小99
    练习题
    练习
    对象、函数
    操作document对象练习
    练习题
    0513-2
    0513-1
  • 原文地址:https://www.cnblogs.com/geekX/p/11466046.html
Copyright © 2011-2022 走看看