[{"text":"衣服类",
"id":"5", //注意:这里是该节点的id,拼连接时要用到,与官方的json有所不同
"leaf":true,
"cls":"file",
"description":"这里是衣服类"}] //自定义只需要这样就可以了
给出java产生json的代码逻辑片断:
……
//list为由传入的id所求的category集合
List list=
findBy("parentId", new Long(parentId.toString()));
StringBuffer JSONStr = new StringBuffer(); //声明json
JSONStr.append("[");
for(CostCategory i : list){
boolean isLeaf = isLeaf(i.getId()); //isLeaf()为判断是否有以该id为parentId的节点,具体没有给出
String icon = isLeaf?"file":"folder";
String description = i.getCategoryDescription()==null?"":i.getCategoryDescription();
//{"text":"treedata.jsp","id":"treedata.jsp","leaf":true,"cls":"file"},
JSONStr.append("{\"text\":\""+
i.getCategoryName()+"\",\"id\":\""+
i.getId()+"\",\"leaf\":"+
isLeaf+",\"cls\":\""+
icon+"\",\"description\":\""+
description+"\"},");
}
JSONStr.deleteCharAt(JSONStr.lastIndexOf(","));
JSONStr.append("]");
System.out.println(JSONStr);
out.print(JSONStr); //输出json
……
关于树TreePanel(Part 2异步获取节点)(2)
内容版权声明:除非注明,否则皆为本站原创文章。