当前位置: 代码迷 >> Web前端 >> Easyui中Tree例证
  详细解决方案

Easyui中Tree例证

热度:367   发布时间:2013-10-18 20:53:13.0
Easyui中Tree例子

最近项目需要用到easyui中的tree,在使用的过程中发现了一些问题,现在将这些总结如

1、用到的属性有:id,text,state,children,checked

2、当有子节点的时候,在添加state属性,如果先添加state=“closed”,会出现空的文件夹点击时会继续加载整棵树

?

前台页面

<!DOCTYPE HTML>

<html lang="en-US">

<head>

<title>tree例子</title>

<script type="text/javascript">

$(function(){

//左侧功能树

$('#categoryTree').tree({

checkbox:false, ? //是否有复选框

lines:true, ? ? ? //行线

animate:true, ?//动画效果

url:'zhtxlAction!treeListData.action', //请求url

onClick:function(node){

$(this).tree('toggle', node.target); //切换效果

//点击事件

}

});

});

</script>

</head>

<body>

<!-- 左侧功能树 -->

<ul id="categoryTree"></ul>

</body>

</html>

?

?

后台代码:

?

?//通讯录树列表

public void treeListData(){

try {

//获取公共通讯录节点

Ggtxl g = ggtxlService.selectByPrimaryKey("1");

Map<String, Object> publicMap = new HashMap<String, Object>();

publicMap.put("id", g.getJgDm());

publicMap.put("text", g.getMc());

//获取公共通讯录下的子节点省民政厅

getGgtxlExample();

com.itic.reis.persistence.model.example.zh.txlgl.ZhGgtxlExample.Criteria criteria1 = ggtxlExample.createCriteria();

criteria1.andScbjEqualTo("0");

criteria1.andSjjgDmEqualTo(g.getJgDm());

List<Ggtxl> r1List = ggtxlService.selectByExample(ggtxlExample);//数据库中省级组织机构

if(r1List != null && r1List.size() > 0){

List<Object> sjList = new ArrayList<Object>(); //存放省级map数据

for (Ggtxl ggtxl1 : r1List) {

Map<String, Object> map1 = new HashMap<String, Object>();

map1.put("id", ggtxl1.getJgDm());

map1.put("text", ggtxl1.getMc());

//获取省下的州市级节点

ggtxlExample.clear();

com.itic.reis.persistence.model.example.zh.txlgl.ZhGgtxlExample.Criteria criteria2 = ggtxlExample.createCriteria();

criteria2.andScbjEqualTo("0");

criteria2.andSjjgDmEqualTo(ggtxl1.getJgDm());

List<Ggtxl> r2List = ggtxlService.selectByExample(ggtxlExample);//数据库中的州市级

if(r2List != null && r2List.size() > 0){

List<Object> zsList = new ArrayList<Object>(); //存放州市map数据

for (Ggtxl ggtxl2 : r2List) {

Map<String, Object> map2 = new HashMap<String, Object>();

map2.put("id", ggtxl2.getJgDm());

map2.put("text", ggtxl2.getMc());

//获取区县级节点

ggtxlExample.clear();

com.itic.reis.persistence.model.example.zh.txlgl.ZhGgtxlExample.Criteria criteria3 = ggtxlExample.createCriteria();

criteria3.andScbjEqualTo("0");

criteria3.andSjjgDmEqualTo(ggtxl2.getJgDm());

List<Ggtxl> r3List = ggtxlService.selectByExample(ggtxlExample);//数据库中的区县级

if(r3List != null && r3List.size() > 0){

List<Object> qxList = new ArrayList<Object>();

for (Ggtxl ggtxl3 : r3List) {

Map<String, Object> map3 = new HashMap<String, Object>();

map3.put("id", ggtxl3.getJgDm());

map3.put("text", ggtxl3.getMc());

qxList.add(map3);

}

map2.put("children", qxList);

map2.put("state", "closed");

}

zsList.add(map2);

}

map1.put("children", zsList);

}

sjList.add(map1);

}

publicMap.put("children", sjList);

}

?

//获取个人通讯录根节点

Grtxl gr = grtxlService.selectByPrimaryKey("1");

Map<String, Object> grMap = new HashMap<String, Object>();

grMap.put("id", gr.getJgDm());

grMap.put("text", gr.getMc());

//获取个人通讯录下的一级节点

getGrtxlExample();

com.itic.reis.persistence.model.example.zh.txlgl.ZhGrtxlExample.Criteria criteria4 = grtxlExample.createCriteria();

criteria4.andScbjEqualTo("0");

criteria4.andSjjgDmEqualTo(gr.getJgDm());

List<Grtxl> gr1List = grtxlService.selectByExample(grtxlExample);//数据库中个人通讯录下的一级子节点

if(gr1List != null && gr1List.size() > 0){

List<Object> firstList = new ArrayList<Object>(); //存放一级map数据

for (Grtxl grtxl1 : gr1List) {

Map<String, Object> grMap1 = new HashMap<String, Object>();

grMap1.put("id", grtxl1.getJgDm());

grMap1.put("text", grtxl1.getMc());

//获取个人通讯录下的二级节点

grtxlExample.clear();

com.itic.reis.persistence.model.example.zh.txlgl.ZhGrtxlExample.Criteria criteria5 = grtxlExample.createCriteria();

criteria5.andScbjEqualTo("0");

? ?criteria5.andSjjgDmEqualTo(grtxl1.getJgDm());

List<Grtxl> gr2List = grtxlService.selectByExample(grtxlExample);

if(gr2List != null && gr2List.size() > 0){

List<Object> secondList = new ArrayList<Object>(); //存放二级map数据

for (Grtxl grtxl2 : gr2List) {

Map<String, Object> gr2Map = new HashMap<String, Object>();

gr2Map.put("id", grtxl2.getJgDm());

gr2Map.put("text", grtxl2.getMc());

secondList.add(gr2Map);

}

grMap1.put("children", secondList);

grMap1.put("state", "closed");

}

?

firstList.add(grMap1);

}

grMap.put("children", firstList);

}

?

//创建总List用于存放个人和公共通讯录

List<Object> totalList = new ArrayList<Object>();

totalList.add(publicMap);

totalList.add(grMap);

?

log.info("总通讯录:"+totalList);

responseJSONObject(totalList);

?

?

} catch (Exception e) {

log.info("获取功能树异常",e);

}

}

  相关解决方案