下面是hashmap中的结构:
HashMap hm1=new HashMap();
hm1.put("dept_id","1");
hm1.put("dept_name","部门A");
hm1.put("parent_id","");HashMap hm2=new HashMap();
hm2.put("dept_id","2");
hm2.put("dept_name","部门B");
hm2.put("parent_id","1");HashMap hm3=new HashMap();
hm3.put("dept_id","3");
hm3.put("dept_name","部门C");
hm3.put("parent_id","2");HashMap hm4=new HashMap();
hm4.put("dept_id","4");
hm4.put("dept_name","部门D");
hm4.put("parent_id","1");HashMap hm=new HashMap();
hm.put("1",hm1);
hm.put("2",hm2);
hm.put("3",hm3);
hm.put("4",hm4);如何使用递归或效率最高的方法将hm中的数据遍历成一棵树状结构的hmtl代码?如下图:
部门A
部门B
部门C
部门D
HashMap hm1=new HashMap();
hm1.put("dept_id","1");
hm1.put("dept_name","部门A");
hm1.put("parent_id","");HashMap hm2=new HashMap();
hm2.put("dept_id","2");
hm2.put("dept_name","部门B");
hm2.put("parent_id","1");HashMap hm3=new HashMap();
hm3.put("dept_id","3");
hm3.put("dept_name","部门C");
hm3.put("parent_id","2");HashMap hm4=new HashMap();
hm4.put("dept_id","4");
hm4.put("dept_name","部门D");
hm4.put("parent_id","1");HashMap hm=new HashMap();
hm.put("1",hm1);
hm.put("2",hm2);
hm.put("3",hm3);
hm.put("4",hm4);如何使用递归或效率最高的方法将hm中的数据遍历成一棵树状结构的hmtl代码?如下图:
部门A
部门B
部门C
部门D
解决方案 »
- 复制一个JAVA工程,出现叹号??
- 如何隐藏swt里的table的列?
- 如何使JTable的表列固定大小
- 请问java.net.SocketException: Default SSL context init failed:是什么错误
- FTP客户端中progressbar的问题
- 请教如何删除每行头几个字符
- 大虾你们好,现在我想在JTable加上一列“序号”。请帮忙!
- Connection reset by peer: socket write error
- 关于一个简单的正则表达式。怎么都搞不定。求教
- 分苹果问题
- 如何打印出时间倒数记时的代码?
- 求最简单方式分析String, "AAA:BBB:CCC:DDD:.....:123",得到最后一个:后面的字符串,并判断是否是数字
部门A
部门B
部门C
部门D你可以直接找一个树的js代码。
不需要自己构造一个树结构,很麻烦的。