Easyui-combotree Personal Instances

Source: Internet
Author: User

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" >


<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 ',
width: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>

<body>
<input id= "T1"/>
<a id= "btn1" class= "Easyui-linkbutton" > Get tree selected Values </a>
<a id= "btn2" class= "Easyui-linkbutton" > Get tree Objects </a>
</body>

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 does not correspond to entity classes in the table

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 table

/*
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 (one) default ' 0 ',

' parent_id ' int (one) default NULL,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=76 DEFAULT charset=utf8;< /span>

-- ----------------------------
--Records of resource
-- ----------------------------
INSERT into ' Resource ' VALUES (' 1 ', ' permissions menu ', NULL, ' 0 ', null, ' 999999 ');
INSERT into ' Resource ' VALUES (' 2 ', ' User management ', NULL, ' 0 ', null, ' 1 ');
INSERT into ' Resource ' VALUES (' 3 ', ' post management ', NULL, ' 0 ', null, ' 1 ');
INSERT into ' Resource ' VALUES (' 4 ', ' Resource management ', NULL, ' 0 ', null, ' 1 ');
INSERT into ' Resource ' VALUES (' 5 ', ' User function 1 ', NULL, ' 0 ', null, ' 2 ');
INSERT into ' Resource ' VALUES (' 7 ', ' post function 1 ', ' 333 ', ' 0 ', NULL, ' 3 ');
INSERT into ' Resource ' VALUES (' 60 ', ' resource function 1 ', ' + ', ' 0 ', NULL, ' 4 ');
INSERT into ' Resource ' VALUES (' 61 ', ' Resource function 2 ', ' A ', ' 0 ', NULL, ' 4 ');
INSERT into ' Resource ' VALUES (' 62 ', ' resource function 3 ', ' 2 ', ' 0 ', NULL, ' 4 ');
INSERT into ' Resource ' VALUES (' 63 ', ' resource function 4 ', ' AA ', ' 0 ', NULL, ' 4 ');
INSERT into ' Resource ' VALUES (' 70 ', ' Rights Management ', ' AA ', ' 0 ', null, ' 1 ');
INSERT into ' Resource ' VALUES (' 75 ', ' Rights Management ', ' 0 ', ' + ', ' null ', ' + ');

Easyui-combotree Personal Instances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.