zTree, 반복

1622 단어
zTree, 반복

/**
*
* @return
*/
public void getHistroyTree(){
histroyTree=this.histroyTreeService.getHistroyTree();
JSONObject json = new JSONObject();
PrintWriter out = null;
try{
Map maps=new HashMap();
for(Object o : histroyTree){
TbDfzTree t=(TbDfzTree)o;
maps.put(t.getId(), t);
}
TbDfzTree root=null;
for(Object o : histroyTree){
TbDfzTree t=(TbDfzTree)o;
if(t.getFid()!=null){
maps.get(t.getFid()).addChild(t);
}else{
root=t;
}
}
root=maps.get(1l);
processtree(root,json);
this.getResponse().setCharacterEncoding("UTF-8");
out = this.getResponse().getWriter();
out.print(json.toString());
out.flush();
out.close();
}catch(Exception ex){
ex.printStackTrace();
}
}


public void processtree(TbDfzTree root,JSONObject json){
json.put("id", root.getId());
json.put("pid", "0");
json.put("name", root.getName());
json.put("isParent", root.getChilds().size()>0);
if(root.getChilds().size()>0){
JSONArray jarray = new JSONArray();
json.put("children",jarray);
for(TbDfzTree item: root.getChilds()){
JSONObject son = new JSONObject();
processtree(item,son);
jarray.add(son);
}
}
}

좋은 웹페이지 즐겨찾기