zoukankan      html  css  js  c++  java
  • Extjs Json树封装

    public class TreeUtil {
     public static List<CTree>getTree(List<Tree> list){
      List<CTree> tree= new ArrayList<CTree>();
      List<CTree> parent= new ArrayList<CTree>();
      List<CTree> chil =new ArrayList<CTree>();
      if(list==null){
       return tree;
      }
      for(Tree ca:list){
       if(ca.getLeaf()==0){//取出所有根节点
        CTree pt=new CTree();
        pt.setId(ca.getId());
        pt.setCid(ca.getCid());
        pt.setCls(ca.getCls());
        pt.setText(ca.getText());
        parent.add(pt);
       }else{//取出所有子节点
        CTree ch=new CTree();
        ch.setId(ca.getId());
        ch.setCid(ca.getCid());
        ch.setCls(ca.getCls());
        ch.setText(ca.getText());
        ch.setUrl(ca.getUrl());
        ch.setLeaf(ca.getLeaf()==1?true:false);
        chil.add(ch);
       }
      }
      for(CTree pr:parent){
       List<CTree> child= new ArrayList<CTree>();
       for(CTree cd:chil){
        if(pr.getCid()==cd.getCid()){
         child.add(cd);
         pr.setChildren(child);
        }
       }
       tree.add(pr);
      }
     
      return tree;
      
     }
    }

    package com.byd.entity;

    import java.io.Serializable;

    @SuppressWarnings("serial")
    public class Tree implements Serializable{
     private String text;
     private int id;
     private int leaf;
     private String cls;
     private String url;
     private int cid;//类别ID

     public Tree(){
      
     }
     /**
      * @return the text
      */
     public String getText() {
      return text;
     }
     /**
      * @param text the text to set
      */
     public void setText(String text) {
      this.text = text;
     }
     
     
     /**
      * @return the cls
      */
     public String getCls() {
      return cls;
     }
     /**
      * @param cls the cls to set
      */
     public void setCls(String cls) {
      this.cls = cls;
     }
     /**
      * @return the cid
      */
     public int getCid() {
      return cid;
     }
     /**
      * @param cid the cid to set
      */
     public void setCid(int cid) {
      this.cid = cid;
     }
     /**
      * @return the leaf
      */
     public int getLeaf() {
      return leaf;
     }
     /**
      * @param leaf the leaf to set
      */
     public void setLeaf(int leaf) {
      this.leaf = leaf;
     }

     /**
      * @return the id
      */
     public int getId() {
      return id;
     }
     /**
      * @param id the id to set
      */
     public void setId(int id) {
      this.id = id;
     }
     /**
      * @return the url
      */
     public String getUrl() {
      return url;
     }
     /**
      * @param url the url to set
      */
     public void setUrl(String url) {
      this.url = url;
     }
    }

  • 相关阅读:
    [Zjoi2014]力(FFT,卷积)
    LOJ 6240. 仙人掌
    Web 服务编程技巧和诀窍: 将 <xsd:any/> 元素用于自定义序列化(转)
    Ant工具使用说明(转)
    Web 服务编程技巧与窍门: 用 SAAJ 和 JAXRPC 构建 SOAP 响应信封(转)
    Axis2 quick start 中文版
    使用SOAP开发java web服务Axis开发方案(转)
    k 动画脚本很有算法 同时可以借鉴这里的画圆
    ui 界面美观化 (多维子材质脚本)
    系类函数介绍 之中可能没有一些预订变量 应用时要自己加上。
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606948.html
Copyright © 2011-2022 走看看