java递归组装easyui combotree


      @Transactional(readOnly=true)
      public String comboxTreeGroup() throws Exception{
                    String data=null;
                  JSONArray jsons =builderComboTree(0);
                  data=jsons.toString();      
            return data;
      }

      @Transactional(readOnly=true)
      public JSONArray builderComboTree(int parentid)throws Exception{
            JSONArray jsons= new JSONArray();
            JSONObject json=null;
            String sql="select id,g_name text,g_parent from permission_groups where g_status=0 and g_parent=?";
            List > lis = (List>) getDao().executeSQLQuery(sql,parentid);
        if (null!=lis&&lis.size()>0) {
            for (Map map : lis) {
                json= new JSONObject(map);
                Integer parent=(Integer) map.get("id");
                 JSONArray tempjson=builderComboTree(parent);
                 if (tempjson.length()>0) {
                    json.put("children", tempjson);
                }
                 jsons.put(json);
            }
        }
        return jsons;
    }


组装后的数据为:
[
   {
      "g_parent" : 0,
      "id" : -2,
      "text" : "未分组用户"
   },
   {
      "children" : [
         {
            "children" : [
               {
                  "g_parent" : 10,
                  "id" : 6,
                  "text" : "市委"
               },
               {
                  "g_parent" : 10,
                  "id" : 7,
                  "text" : "市人大"
               },
               {
                  "g_parent" : 10,
                  "id" : 8,
                  "text" : "市政协"
               },
               {
                  "g_parent" : 10,
                  "id" : 9,
                  "text" : "市纪委"
               }
            ],
            "g_parent" : 1,
            "id" : 10,
            "text" : "几套班子"
         },
         {
            "children" : [
               {
                  "g_parent" : 11,
                  "id" : 2,
                  "text" : "禅城区人民政府"
               },
               {
                  "g_parent" : 11,
                  "id" : 3,
                  "text" : "南海区人民政府"
               },
               {
                  "g_parent" : 11,
                  "id" : 4,
                  "text" : "三水区人民政府"
               },
               {
                  "g_parent" : 11,
                  "id" : 5,
                  "text" : "顺德区人民政府"
               }
            ],
            "g_parent" : 1,
            "id" : 11,
            "text" : "各区政府"
         },
         {
            "children" : [
               {
                  "g_parent" : 12,
                  "id" : 13,
                  "text" : "市中级人民法院 "
               },
               {
                  "g_parent" : 12,
                  "id" : 14,
                  "text" : "市人民检察院"
               }
            ],
            "g_parent" : 1,
            "id" : 12,
            "text" : "法院、检察院"
         },
         {
            "children" : [
               {
                  "g_parent" : 15,
                  "id" : 16,
                  "text" : "市委办公室 "
               },
               {
                  "g_parent" : 15,
                  "id" : 17,
                  "text" : "市委组织部"
               }
            ],
            "g_parent" : 1,
            "id" : 15,
            "text" : "市委工作部门"
         }
      ],
      "g_parent" : 0,
      "id" : 1,
      "text" : "佛山市人民政府"
   }
]

java递归组装easyui <wbr>combotree


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值