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);
}