您的位置:首页 > 产品设计 > UI/UE

EasyUI combotree 使用递归动态填数据

2016-09-10 19:47 162 查看
public JSONArray getDepTree()throws Exception{
List<IntroWebCat> deps=Dao.GetParentIdTree();
JSONArray array=new JSONArray();
JSONObject o= new JSONObject();
o.put("id",0);
o.put("text","无");
array.add(o);
for(IntroWebCat d :deps){
if(d.getParentId()==null){
JSONObject temp=new JSONObject();
temp.put("id",d.getId());
temp.put("text",d.getCatName());
temp.put("state","open");
putTreeChild(temp, deps, d.getId());
array.add(temp);
}
}
return array;
}

private void putTreeChild(JSONObject obj,List<IntroWebCat> list,Integer parId){
JSONArray array=new JSONArray();
for(IntroWebCat d :list){
if(parId.equals(d.getParentId()) ){
JSONObject temp=new JSONObject();
temp.put("id",d.getId());
temp.put("text",d.getCatName());
temp.put("state","open");
putTreeChild(temp, list, d.getId());
array.add(temp);
}
}
if(!array.isEmpty())
obj.put("children",array);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: