自定义类 无极限树形结构菜单(繁杂版)

注意: 主要是理解形成树形菜单的思路,并不是粘贴就可以用的。

  返回数据(如:效果图)到页面后,通过js做递归调用处理就好了。


树形菜单基础类: TreeGridCategory.java

public class TreeGridCategory implements Comparable{
        private String id;											/* ID */
	private String name;										/* 名称 */
	private String path;										/* 图标 */
	private String pid;											/* 父级ID */
	private String level;
	private String state="close";								/* 折叠状态 */
	private String lang;
	private String sort;
	private String status;
	private String leaf;				/* 叶子节点标识:1:子节点 2:叶子节点 */
        Map params  = new HashMap();
        List children = new ArrayList();		/* 子集节点 */



mybatis 查询:


	


业务层处理:

        @Override
      public List getTreeGridCategory(VodCategory vodCategory) {
         List easyuiTreetemp = new ArrayList();
		Map map=new HashMap();
		map.put("lang","zh-cn");
                List> dataList = tVodCategoryDao.getVodCategory(map);
		Map treeMap = new HashMap<>();
                for (Map easyuiTreeMap : dataList) {
			TreeGridCategory treeGridCategory = fomateTreeGridCategory(easyuiTreeMap);
			treeMap.put(treeGridCategory.getId(), treeGridCategory);
			easyuiTreetemp.add(treeGridCategory);
		}
		List treeGridList = new ArrayList();
                for (int i = 0; i < easyuiTreetemp.size(); i++) {
			TreeGridCategory tempTree = easyuiTreetemp.get(i);
			TreeGridCategory mapTree = treeMap.get(tempTree.getPid());
			if(null != mapTree && !tempTree.getId().equals(tempTree.getPid())){
				mapTree.getChildren().add(tempTree);
			}else{
				treeGridList.add(tempTree);
			}
		}
		return treeGridList;
        }

       private TreeGridCategory fomateTreeGridCategory(Map map){
                TreeGridCategory treeGridCategory = new TreeGridCategory();
		Map params = new HashMap();
		for (String key : map.keySet()) {
               switch (key) {
			case "id":
				treeGridCategory.setId(map.get(key)+"");
				break;
			case "name":
				treeGridCategory.setName(map.get(key)+"");
				break;
			case "path":
				treeGridCategory.setPath(map.get(key)+"");
				break;
			case "pid":
				treeGridCategory.setPid(map.get(key)+"");
				break;
			case "leaf":
				treeGridCategory.setLeaf(map.get(key)+"");
				break;
			case "sort":
				treeGridCategory.setSort(map.get(key) + "");
				break;
                        case "level":
				treeGridCategory.setLevel(map.get(key) + "");
				break;
			case "lang":
				treeGridCategory.setLang(map.get(key)+"");
				break;
			case "status":
				treeGridCategory.setStatus(map.get(key)+"");
				break;
			default:
				params.put(key, map.get(key));
				break;
			}
		}
             treeGridCategory.setParams(params);
		return treeGridCategory;
	}

控制层:

List list = new ArrayList();
list = treeGridService.getTreeGridCategory(vodCategory);
return  list;


Js 上递归处理:

function getHtml(jsonArr){
	for(var i=0;i';
		else 
			html += '';
		html += ''+jsonArr[i].id+'';
		html += ''+jsonArr[i].name+'';
		if(jsonArr[i].path!=null){
			html += '';
		}else{
			html += '';
		}
		
		html += ''+jsonArr[i].lang+'';
		html += ''+jsonArr[i].sort+'';
		if(jsonArr[i].status=="0" ){
			html += '';
		}else{
			html += '';
		}
		
		html += '';
		if(jsonArr[i].status=="0" ){
			html += ' ';
		}else{
			html += ' ';
		}
		
		html +='';
		if(jsonArr[i]['children'] != null || jsonArr[i]['children'] != '' ){
			getHtml(jsonArr[i]['children']);
		}
	}
}



你可能感兴趣的:(java)