EasyUI树目录结构,通过后台返回的json数据resualt,通过eval()解析成对象给treeData
从而实现动态数据:下面是treeData 数据默认的数据格式:
//动态菜单数据

var treeData = [{text :  "菜单",children :  [{text :  "一级菜单1",attributes :  {url :  ""                    }                },{text :  "一级菜单2",attributes :  {url :  ""                    }                },{text :  "一级菜单3",state :  "closed",children :  [{text :  "二级菜单1",attributes :  {url :  ""                            }                        },{text :  "二级菜单2",attributes :  {url :  ""                            }                        },{text :  "二级菜单3",attributes :  {url :  ""                            }                        }                    ]                }            ]
}    ];

1、效果:

2、Js实现代码:

$.post(url,function(resualt){//动态菜单数据var treeData =eval("("+resualt+")");//实例化树形菜单$("#tree").tree({data : treeData,lines : true,onClick : function (node) {if (node.attributes) {Open(node.text, node.attributes.url);}}});//在右边center区域打开菜单,新增tabfunction Open(text, url) {//这里将url存放来问类型代码getFwInfo(text,url);}
//-----post end//通过传递的参数访和Url访问后台并返回json数据function getFwInfo(year,lwlxmc){}

3、Html代码:
在页面中添加ul标签, id=”tree”

<ul id="tree"></ul>

4、java实现
思路分析:从treeData 数据

顶级目录以及子目录格式为:

 {text :  "一级菜单3",state :  "closed",children :  [{text :  "二级菜单1",attributes :  {url :  ""                            }                        },{text :  "二级菜单2",attributes :  {url :  ""                            }                        },{text :  "二级菜单3",attributes :  {url :  ""                            }                        }                    ]                } 

从上面可以看出:顶级目录的属性:text 、state 、children 。其中children 是设置子目录的,子目录包含text 、attributes 、url 其中url是attributes 属性节点,所以根据这个格式编写java:
首先创建bean
创建顶级目录bean– Parent.java

package com.bean.guiGangMenu;import java.util.ArrayList;public class Parent {private String text;private ArrayList<Children> children;public String getText() {return text;}public void setText(String text) {this.text = text;}public ArrayList<Children> getChildren() {return children;}public void setChildren(ArrayList<Children> children) {this.children = children;}}

创建子目录bean:

package com.bean.guiGangMenu;public class Children {private Url attributes;private String text;public String getText() {return text;}public void setText(String text) {this.text = text;}public Url getAttributes() {return attributes;}public void setAttributes(Url attributes) {this.attributes = attributes;}}

创建attributes属性bean

package com.bean.guiGangMenu;public class Url {private String url;public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}
}

测试数据集合

String y="2014年";SimpleDateFormat format=new SimpleDateFormat("yyyy年");Date d=new Date();System.out.println(format.format(d));//设置菜单集合父菜单ArrayList<Parent> parent=new ArrayList<Parent>();Parent prnt=new Parent();prnt.setText("父菜单");//设置子菜单集合ArrayList<Children> children=new ArrayList<Children>();Children child=new Children();//设置子菜单名称child.setText("子菜单一");Url rl=new Url();rl.setUrl("http://www.baidu.com");//设置子菜单Urlchild.setAttributes(rl);//添加到子菜单集合中children.add(child);Children child2=new Children();child2.setText("子菜单二");child2.setAttributes(rl);children.add(child2);//父菜单添加子菜单prnt.setChildren(children);//添加到父菜单集合中parent.add(prnt);

输出数据:

[{"text":"父菜单","children":[{"text":"子菜单一","attributes":{"url":"http://www.baidu.com"}},{"text":"子菜单二","attributes":{"url":"http://www.baidu.com"}}]}]

正式调用:

@RequestMapping("/getMenuClassifyInfo_sw")public void getMenuClassifyInfo_sw(RcbgSwdjZbModel model,String type, String number,HttpServletRequest request, HttpServletResponse response) throws Exception{SimpleDateFormat format=new SimpleDateFormat("yyyy年");response.setCharacterEncoding("utf-8");PrintWriter writer = response.getWriter();List<RcbgSwdjZb> getFwcx = get_swcx(model,response,request);//设置菜单集合父菜单ArrayList<Parent> parent=new ArrayList<Parent>();//国家局菜单集合HashSet countrySet=new HashSet();//省部委HashSet provinceSet=new HashSet();//无文号HashSet noNumSet=new HashSet();for(RcbgSwdjZb fwzb:getFwcx){if(fwzb.getLwlx()!=null){Parent prnt=new Parent();if(fwzb.getLwlx().equals("0001")){// prnt.setText("收文库(国家局)");if(fwzb.getSwrq()!=null){String year=format.format(fwzb.getSwrq());countrySet.add(year);}}if(fwzb.getLwlx().equals("0002")){ // prnt.setText("收文库(省、部、委)");if(fwzb.getSwrq()!=null){String year=format.format(fwzb.getSwrq());provinceSet.add(year);}}if(fwzb.getLwlx().equals("0003")){ //prnt.setText("无文号登记");if(fwzb.getSwrq()!=null){String year=format.format(fwzb.getSwrq());noNumSet.add(year);}}}}//HashSet set=new HashSet();for(int i=0;i<3;i++){Parent prnt=new Parent();Iterator<String> itor=null;if(i==0){prnt.setText("收文库(国家局)");itor=countrySet.iterator();}if(i==1){prnt.setText("收文库(省、部、委)");itor=provinceSet.iterator();}if(i==2){prnt.setText("无文号登记");itor=noNumSet.iterator();}if(itor.hasNext()==false){ArrayList<Children> children=new ArrayList<Children>();Children child=new Children();//设置子菜单名称child.setText("无");Url rl=new Url();rl.setUrl("http://www.baidu.com");//设置子菜单Urlchild.setAttributes(rl);//添加到子菜单集合中children.add(child);//父菜单添加子菜单prnt.setChildren(children);//添加到父菜单集合中parent.add(prnt);}else{ArrayList<Children> children=new ArrayList<Children>();for(Iterator<String> it=itor;it.hasNext();){String menu=it.next();Children child=new Children();//设置子菜单名称child.setText(menu);Url rl=new Url();if(i==0)rl.setUrl("0001");if(i==1)rl.setUrl("0002");if(i==2)rl.setUrl("0003");//设置子菜单Urlchild.setAttributes(rl);//添加到子菜单集合中children.add(child);}//父菜单添加子菜单prnt.setChildren(children);//添加到父菜单集合中parent.add(prnt);}}String menu=JSONUtil.toJSONString(parent);writer.write(menu);writer.close();5、  }

6、最终就是刚开始看到的树目录:

EasyUI树目录结构相关推荐

  1. easyUI的目录结构

    easyUI的目录结构 easyUI从官网下载下来之后,一般都是有一个完整的目录结构,目前官网的最新版本是jquery-easyui-1.5.1,如下. 文件说明 Demo:是easyUI的使用示例, ...

  2. linux如何查看树目录结构,Linux查看目录结构树之tree命令

    1. tree命令简介 本文主要讲解如何查看Linux的目录结构,有时我们需要查看某目录里的结构,使用cd命令一层层查看显然不实际,效率也不高,这是可以使用tree命令,Linux tree命令用于以 ...

  3. file类打印目录---树状结构,递归

    package Test; import java.io.File; /** * file类打印目录---树状结构,递归 * @author Administrator * */ public cla ...

  4. 基于easyui开发Web版Activiti流程定制器详解(一)——目录结构

     题外话(可略过): 前一段时间(要是没记错的话应该是3个月以前)发布了一个更新版本,很多人说没有文档看着比较困难,所以打算拿点时间出来详细给大家讲解一下,由于本人平时要工作还要陪老婆和孩子而且还 ...

  5. 【转】基于easyui开发Web版Activiti流程定制器详解(一)——目录结构

    题外话(可略过): 前一段时间(要是没记错的话应该是3个月以前)发布了一个更新版本,很多人说没有文档看着比较困难,所以打算拿点时间出来详细给大家讲解一下,由于本人平时要工作还要陪老婆和孩子而且还经营着 ...

  6. php删除树结构文件,树型结构列出目录中所有文件的php代码

    以树型结构列出指定目录里的所有文件,这样的话,目录下的所有文件便结构清晰的呈现在你的面前,有什么文件你一看便知,很方便的哦. 示例, php; auto-links:false;"> ...

  7. windows和linux打印树状目录结构

    windows下有tree命令可以打印出树状目录结构,linux下也有这个命令. 1.windows下tree命令 cmd窗口中查看帮助: tree /? 以图形显示驱动器或路径的文件夹结构. TRE ...

  8. 大厂出品的免费精品Markdown文档编辑器推荐,支持无限树状目录结构

    前言 最近markdown文档写的比较多,就想找一个喜欢的markdown编辑器,支持文档树状目录结构的那种,网上搜了一些,发现大部分并不支持树状目录,要不就是界面实在太丑,或者太卡顿.基本都试用了一 ...

  9. 【批处理DOS-CMD命令-汇总和小结】-显示目录结构/文件树——dir、tree

    一.显示文件/目录列表:dir 1.1 打印dir命令帮助信息 C:\Users\Administrator\Downloads\Music>dir /? 显示目录中的文件和子目录列表.DIR ...

最新文章

  1. 二维数组c语言矩阵加法,C 语言实例 – 两个矩阵相加 - C 语言基础教程
  2. Shared——The best front-end hacking cheatsheets — all in one place.
  3. com.android.ddmlib.ShellCommandUnresponsiveException
  4. mysql replace into 使用过程中报错
  5. oracle json字符串转数组,json字符串转化成json对象(原生方法)
  6. ROS机器人导航仿真(kinetic版本)
  7. c专家编程 读书笔记
  8. bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路(A*第k短路)
  9. 数据结构:实验四 图的遍历
  10. 据说每年有四分一的房地产项目烂尾,房子都是预售的钱哪里去了?
  11. 2019python全栈第22期百度云_2019年最新老男孩Python全栈第22期
  12. java倒序输出英文句子_Java实现英文句子中的单词顺序逆序输出的方法
  13. chrome18-使用network waterfall分析页面载入性能
  14. 为什么amd显卡便宜却买的人少_这7张显卡现在最好不要买,千万不要花钱当冤大头...
  15. 【luogu P5320】勘破神机(数学)(数列特征方程)(第一类斯特林数)
  16. LM2576在嵌入式系统中的应用
  17. [BJOI2006]狼抓兔子
  18. 高性能mysql学习笔记--高级特性
  19. 哪位兄台能优化这条SQL语句,在线等,捉急!!!
  20. Eureka注册发现及Feign调用示例

热门文章

  1. 肖申克的救赎 经典语录
  2. linux syscall 详解
  3. 你的“脸”正在被交易
  4. 数据库操作语言——DML语言
  5. mysql查询高于部门平均工资_Oracle数据库中 查询高于自己部门平均工资的员工信息 用相关子查询怎么做啊?...
  6. iptv不稳定是服务器问题吗,IPTV仍面临很多问题
  7. iReport3.0.0属性说明
  8. Bootstrap 响应式实用工具——visible-xs、visible-sm、hidden-xs、hidden-sm等
  9. EDI 820 付款委托书或汇款通知
  10. 为centos 7 安装图形化桌面环境