• easyui-combotree个人实例


    1.combotree.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css"
    href="<%=path%>/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
    href="<%=path%>/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/easyui/demo.css">
    <script type="text/javascript"
    src="<%=path%>/easyui/jquery-1.7.2.min.js"></script>
    <script type="text/javascript"
    src="<%=path%>/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("#t1").combotree({
    url:'/egoTest/tree/loadTree.do',
    300,
    checkbox:true,
    multiple:true

    });

    $("#btn1").click(function(){
    console.info($("#t1").combotree('getValue'));
    });

    $("#btn2").click(function(){
    var tree = $("#t1").combotree('tree');
    var root = tree.tree('getRoot');
    console.info(root);
    });
    });
    </script>
    <title>Insert title here</title>
    </head>
    <body>
    <input id="t1"/>
    <a id="btn1" class="easyui-linkbutton">获取tree选中的值</a>
    <a id="btn2" class="easyui-linkbutton">获取tree对象</a>
    </body>
    </html>

    2.TreeController.java

    @RequestMapping("/loadTree")
    public void getAjaxUser(HttpServletRequest request,
    HttpServletResponse response, ModelMap modelMap, Page page) {
    try {
    String id = request.getParameter("id");
    response.setContentType("text/html;charset=utf-8");
    List<TreeVO> tList = treeService.queryTree(id);
    response.getWriter().write(JSONArray.fromObject(tList).toString());
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    3.treeService.java

    public List<TreeVO> queryTree(String id) {
    List<Resource> rList = treeDao.queryTree(id);

    List<TreeVO> tList = new ArrayList<TreeVO>();
    for (Iterator iterator = rList.iterator(); iterator.hasNext();) {
    Resource resource = (Resource) iterator.next();
    TreeVO tree = new TreeVO();
    tree.setId(resource.getId());
    tree.setText(resource.getName());
    tree.setChecked(resource.getChecked());
    tree.setIconCls(resource.getIcons());
    tree.setParent_id(resource.getParent_id());
    if(treeDao.queryTree(String.valueOf(resource.getId())).size() > 0){
    tree.setState("closed");
    }else{
    tree.setState("open");
    }
    Map<String,Object> map = new HashMap<String,Object>();
    map.put("url", resource.getUrl());
    tree.setAttributes(map);
    tList.add(tree);
    }
    return tList;
    }

    4.Resource.java

    private int id;
    private String name;
    private String url;
    private int checked;
    private String icons;
    private int parent_id;

    5.treeVO.java   不用与表中的实体类对应

    private int id;
    private String text;
    private String iconCls;
    private int checked;
    private int parent_id;
    private String state;
    private Map<String, Object> attributes = new HashMap<String, Object>();

    public TreeVO(){}


    public TreeVO(int id, String text, String iconCls, int checked,
    int parent_id, String state, Map<String, Object> attributes) {
    super();
    this.id = id;
    this.text = text;
    this.iconCls = iconCls;
    this.checked = checked;
    this.parent_id = parent_id;
    this.state = state;
    this.attributes = attributes;
    }

    6.resource表

    /*
    Navicat MySQL Data Transfer

    Source Server : mysql_client
    Source Server Version : 50045
    Source Host : 127.0.0.1:3306
    Source Database : salesproject

    Target Server Type : MYSQL
    Target Server Version : 50045
    File Encoding : 65001

    Date: 2015-10-18 07:38:25
    */

    SET FOREIGN_KEY_CHECKS=0;

    -- ----------------------------
    -- Table structure for resource
    -- ----------------------------
    DROP TABLE IF EXISTS `resource`;
    CREATE TABLE `resource` (
    `id` int(11) NOT NULL auto_increment,
    `name` varchar(255) default NULL,
    `url` varchar(255) default NULL,
    `checked` int(11) default '0',
    `icons` varchar(255) default NULL,
    `parent_id` int(11) default NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=76 DEFAULT CHARSET=utf8;

    -- ----------------------------
    -- Records of resource
    -- ----------------------------
    INSERT INTO `resource` VALUES ('1', '权限菜单', null, '0', null, '999999');
    INSERT INTO `resource` VALUES ('2', '用户管理', null, '0', null, '1');
    INSERT INTO `resource` VALUES ('3', '岗位管理', null, '0', null, '1');
    INSERT INTO `resource` VALUES ('4', '资源管理', null, '0', null, '1');
    INSERT INTO `resource` VALUES ('5', '用户功能1', null, '0', null, '2');
    INSERT INTO `resource` VALUES ('7', '岗位功能1', '333', '0', null, '3');
    INSERT INTO `resource` VALUES ('60', '资源功能1', '31', '0', null, '4');
    INSERT INTO `resource` VALUES ('61', '资源功能2', '34', '0', null, '4');
    INSERT INTO `resource` VALUES ('62', '资源功能3', '2', '0', null, '4');
    INSERT INTO `resource` VALUES ('63', '资源功能4', 'aa', '0', null, '4');
    INSERT INTO `resource` VALUES ('70', '权限管理', 'aa', '0', null, '1');
    INSERT INTO `resource` VALUES ('75', '权限管理11', '66', '0', null, '70');

  • 相关阅读:
    【洛谷6620】[省选联考 2020 A 卷] 组合数问题(下降幂)
    【AtCoder】AtCoder Grand Contest 033 解题报告
    【AtCoder】AtCoder Grand Contest 034 解题报告
    【洛谷5445】[APIO2019] 路灯(树套树)
    【LOJ6059】「2017 山东一轮集训 Day1」Sum(倍增优化数位DP+NTT)
    【LOJ6159】「美团 CodeM 初赛 Round A」最长树链(树的直径)
    重新入门的Polya定理
    【洛谷6105】[Ynoi2010] y-fast trie(set)
    【BZOJ4480】 [JSOI2013] 快乐的jyy(回文自动机裸题)
    【LOJ6172】Samjia 和大树(树形DP+猜结论)
  • 原文地址:https://www.cnblogs.com/cxxjohnson/p/4888863.html
Copyright © 2020-2023  润新知