要想用easyui生成一个树形结构的表格,首先你当然需要使你的数据结构和要求的一致,比如说id,textparentIdstatechildren这些必须的参数,也可以根据自己的需求加额外的参数,比如url等。So,就先来建一个类

publicclass TreeNode {

    private Integer id;

    private String text;

    private Integer parentId;

    private String state;

    private List< TreeNode > children;

    public TreeNode () {

    }

    public TreeNode (Integer id, String text, Integer parentId, String state, List< TreeNode> children) {

       super();

       this.id = id;

       this.text = text;

       this.parentId = parentId;

       this.state = state;

       this.children = children;

    }

..省略getter/setter..

}

前台放一个table就可以了,当然这里面的参数可以根据要求添加

<table id="dg" class="easyui-treegrid" data-options="fit:true,fitColumns:true,        url:'${pageContext.request.contextPath}/XX/XX/XXX',

idField:'id',treeField:'text'">

后台根据url地址找到之后,得先取出原本的数据,然后赋值给Node,返回的也是TreeNode类型的list,就像下面这样,省去赋值的部分了,直接找到根节点和叶子节点

    public List XXX(){

        Listcals = pageMapper.getRoot();

        Listpages = pageMapper.getLeaf();

        for(TreeNode c :cals){

            c.setChildren(getChildren(c.getId(), pages));

        }

       return cals;

    }

   

    private List getChildren(Integer id,Listpages){

       List cs = new ArrayList();

       for(TreeNode tn : pages){

           if(id.equals(tn.getParentId())){

              cs.add(tn);

           }

       }

       return cs;

    }