zoukankan      html  css  js  c++  java
  • 字符串解析成easyui-tree的格式

    传入的list:

    [30 : null : null, 301503 : null : null, 301501 : null : null, 301502 : null : null, 3015 : null : null]

    解析后的json:

      1 public class LeftTreeBean {
      2     public StringBuilder getTreeMenus(List lst, String contextPath) {
      3         StringBuilder model = new StringBuilder("");
      4         String RightName = "";
      5         String RightURL = "";
      6 
      7         Map rightMap = new HashMap();
      8 
      9 //        for (RightObject ro : (ArrayList) lst) {
     10         for (Object ro : lst) {
     11             ro = (RightObject)ro;
     12             String parentId = ((RightObject) ro).getParentID();
     13 
     14             if ((parentId == null) || (parentId.trim().length() == 0)
     15                     || (parentId.equalsIgnoreCase("0"))) {
     16                 parentId = "0";
     17             }
     18             if (!rightMap.containsKey(parentId)) {
     19                 rightMap.put(parentId, new ArrayList());
     20             }
     21 
     22             ((List) rightMap.get(parentId)).add(ro);
     23         }
     24 
     25         List lro = (List) rightMap.get("0");
     26 
     27         if (lro != null) {
     28             model.append("[");
     29 
     30             Map mt = ConfUtil.getMenus();
     31 
     32 //            for (RightObject ro : lro) {
     33             for (Object ro : lro) {
     34                 ro = (RightObject)ro;
     35                 RightName = (String) ((Map) mt.get(((RightObject) ro).getRightID()))
     36                         .get("RIGHTNAME");
     37                 RightURL = "";
     38 
     39                 model.append('{').append("key:")
     40                         .append(JSONUtilities.quote(((RightObject) ro).getRightID()))
     41                         .append(",title:")
     42                         .append(JSONUtilities.quote(RightName));
     43 
     44                 if (rightMap.containsKey(((RightObject) ro).getRightID())) {
     45                     model.append(",isFolder:true,children:[
    ");
     46 
     47                     for (RightObject ro2 : (List) rightMap.get(ro.getRightID())) {
     48                         Map rItem = (Map) mt.get(ro2.getRightID());
     49                         if (rItem != null) {
     50                             RightName = (String) rItem.get("RIGHTNAME");
     51 
     52                             model.append("	{")
     53                                     .append("key:")
     54                                     .append(JSONUtilities.quote(ro2
     55                                             .getRightID())).append(",title:")
     56                                     .append(JSONUtilities.quote(RightName));
     57 
     58                             if (rightMap.containsKey(ro2.getRightID())) {
     59                                 model.append(",isFolder:true,children:[
    ");
     60 
     61                                 for (RightObject ro3 : (List) rightMap.get(ro2
     62                                         .getRightID())) {
     63                                     if (mt.containsKey(ro3.getRightID())) {
     64                                         RightName = (String) ((Map) mt.get(ro3
     65                                                 .getRightID()))
     66                                                 .get("RIGHTNAME");
     67                                         RightURL = (String) ((Map) mt.get(ro3
     68                                                 .getRightID())).get("URL");
     69                                         String BUSSFUNCID = ro3.getBussFuncID();
     70 
     71                                         String split = RightURL.indexOf("?") >= 0 ? "&"
     72                                                 : "?";
     73                                         String url = contextPath
     74                                                 + RightURL.replace('\', '/')
     75                                                 + split + "RightID="
     76                                                 + ro3.getRightID()
     77                                                 + "&_menuID="
     78                                                 + ro3.getRightID() + "&funcID="
     79                                                 + BUSSFUNCID;
     80 
     81                                         model.append("		{")
     82                                                 .append("key:")
     83                                                 .append(JSONUtilities.quote(ro3
     84                                                         .getRightID()))
     85                                                 .append(",title:")
     86                                                 .append(JSONUtilities
     87                                                         .quote(RightName))
     88                                                 .append(",url:")
     89                                                 .append(JSONUtilities
     90                                                         .quote(url))
     91                                                 .append("},
    ");
     92                                     }
     93                                 }
     94                                 model.deleteCharAt(model.length() - 2).append(
     95                                         "		]");
     96                             }
     97                             model.append("},
    ");
     98                         }
     99                     }
    100                     model.deleteCharAt(model.length() - 2).append("	]");
    101                 }
    102                 model.append("},
    ");
    103             }
    104 
    105             model.deleteCharAt(model.length() - 2).append(']');
    106         }
    107 
    108         return model;
    109     }
    110 }
  • 相关阅读:
    net 反射30分钟速成
    Net is as typeof 运行运算符详解
    net 自定义泛型那点事
    博客搬家啦!
    Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7
    原根(扩展欧几里得+欧拉函数)
    2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)
    博弈之——SG模板
    点到圆弧的距离(csu1503)+几何
    Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二
  • 原文地址:https://www.cnblogs.com/Sunnor/p/5823978.html
Copyright © 2011-2022 走看看