本帖最后由 nie_peng 于 2010-09-07 18:05:56 编辑

解决方案 »

  1.   

    http://falchion.javaeye.com/blog/187548
      

  2.   

    想请教具体的代码,关键是那个children 那一块怎么弄,如何循环得到下面的所以children?
      

  3.   

    jQuery EasyUI插件有个异步树适合这种需求
      

  4.   

    public void getEasyTree(String parentId){
            this.id = parentId;
            this.getEasyTreei(parentId);
            json = "[" + json.substring(0, json.length() - 1) + "]";
        }
        public void getEasyTreei(String parentId) {
            childrenId = treeService.getChildrenId(parentId);
            if(childrenId != null){
                json += "{ \"id\":\"" + parentId + "\"";
                json += ", \"text\":\"" + treeService.getName(parentId) + "\"";
                if(parentId == this.id)
                    json += ", \"state\":\"open\"";
                else if(childrenId.size() > 0)
                    json += ", \"state\":\"closed\"";
                json += ", \"attributes\":{\"departid\":\"" + parentId + "\"}";            if(childrenId.size() > 0){
                    json += ", \"children\":[";
                    for (String child : childrenId){
                        this.getEasyTreei(child);
                    }
                    json = json.substring(0, json.length() - 1);
                    json +=  "]";
                }
                json +=  "},";
            }
        }
      

  5.   

    这种拼法太累,而且如果值中有双引号的话,你浏览器端使用eval解析不出JSON对象。
    使用xml也许会更简单些,然后写个函数把xml转换成json对象.