js 页面加载树形菜单结构

1.通过sql语句查询子父关系结构

select a.eventid as grouppeventid,a.groupname as groupName
from (select t.eventid,
t.groupname,
t.grouppeventid
from gps_groups t
connect by prior t.eventid = t.grouppeventid
start with t.grouppeventid is null
) a
where 1 = 1 ;


2.通过Java获得JSONArray
   
   JSONArray array = treeMenuList(JSONArray.fromObject(resultList));
   //菜单树形结构  
   public JSONArray treeMenuList(JSONArray menuList, int parentId) {  
       JSONArray childMenu = new JSONArray();  
       for (Object object : menuList) {  
           JSONObject jsonMenu = JSONObject.fromObject(object);  
           int menuId = jsonMenu.getInt("id");  
           int pid = jsonMenu.getInt("parentId");  
           if (parentId == pid) {  
               JSONArray c_node = treeMenuList(menuList, menuId);  
               jsonMenu.put("childNode", c_node);  
               childMenu.add(jsonMenu);  
           }  
       }  
       return childMenu;  
   }  


3.通过JS加载到easyui Tree组件上

function filterTree(data){
  var iRtn = [] ;
  for(var i=0;i<=data.length-1;i++){
     var arr = [] ;
     var json = data[i];
     // 转换成Tree所要的格式
     var obj = {} ;
     // 对children进行遍历
     if(json.children && json.children.length>0){
        arr = this.filterTree(json.children);
     }
     obj.children = arr ;
     iRtn.push(arr);
  }
  return iRtn ;
}

initTree:function(){
		$("#xxx").tree({    
		    url:"xxxx.action",  
		    lines:true,
		    loadFilter: function(e){  
		    	return this.filterTree(e.items);
		    },
			onClick:function(node){
				xx.curnode=node;
				xxx.treeData2Form(node.menu);
			}
		}); 
	},



















你可能感兴趣的:(js 页面加载树形菜单结构)