码迷,mamicode.com
首页 > 编程语言 > 详细

java实现一个树形列表

时间:2017-12-11 14:25:38      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:ext   imp   页面   oct   v-cloak   tcl   menu   dao   long   

1.页面:

<!DOCTYPE html>
<html>
<head>
<title>所属机构</title>
#parse("include/header.html")
</head>
<body>
    <div id="dpLTE" class="container-fluid" v-cloak>
        <ul id="orgTree" class="ztree"></ul>
    </div>
    #parse("include/footer.html")
    <script type="text/javascript">
    var setting = {
        data : {
            simpleData : {
                enable : true,
                idKey : "orgId",
                pIdKey : "parentId",
                rootPId : 0
            },
            
        }
    };
    var ztree;

    var vm = new Vue({
        el : #dpLTE,
        data : {
            orgId : ‘‘,
            orgName: ‘‘
        },
        methods : {
            getOrg : function(menuId) {
                $.get(../../sys/org/selectOrgPermi?_ + $.now(), function(r) {
                    ztree = $.fn.zTree.init($("#orgTree"), setting, r);
                })
            },
            acceptClick: function() {
                var node = ztree.getSelectedNodes();
                var org = new Array();
                org[0] = node[0].orgId;
                org[1] = node[0].name;
                dialogClose();
                return org;
            }
        },
        created : function() {
            this.getOrg();
        }
    })
    </script>
</body>
</html>

2.后台代码:

public List<SysOrgDO> listTree(Long parentId, boolean bol) {
        List<SysOrgDO> orgList = new ArrayList<SysOrgDO>();
        findOrgTreeByParentId(parentId, orgList, bol);
        SysOrgDO org = new SysOrgDO();
        org.setOrgId(parentId);
        org.setName("ROOT");
        org.setParentId(-1L);
        org.setOpen(true);
        orgList.add(org);
        return orgList;
    }
    


/**
     * 树形查找
     * @param parentId
     * @param list
     * @param bol 是否查找多级子节点
     */

    private void findOrgTreeByParentId(Long parentId, List<SysOrgDO> list, boolean bol) {
        BaseQuery query = new BaseQuery();
        query.put("parentId", parentId);
        List<SysOrgDO> orgList = sysOrgDao.list(query);
        if (orgList != null &&  orgList.size() > 0) {
            list.addAll(orgList);
            if(bol){
                for(SysOrgDO sdo : orgList){
                    findOrgTreeByParentId(sdo.getOrgId(), list, bol);
                }
            }
        }else{
            return;
        }
    }

3.sql:

SELECT
            t.org_id,
            t.parent_id,
            (
                SELECT
                    p.name
                FROM
                    sys_org p
                WHERE
                    p.org_id = t.parent_id
            ) AS parentName,
            t.channel_id,
            (
                SELECT
                    p.name
                FROM
                    sys_org p
                WHERE
                    p.org_id = t.channel_id
            ) AS channelName
 FROM
            sys_org t    

 

java实现一个树形列表

标签:ext   imp   页面   oct   v-cloak   tcl   menu   dao   long   

原文地址:http://www.cnblogs.com/tengfeihhh/p/8022226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!