ExtJS, the realization of the tree-shaped structure of the summary

Source: Internet
Author: User

Work summary, with ExtJS, MyBatis, Springmvc to realize the tree-shaped display class

The foreground ExtJS implements the tree code as follows:

Xtype: ' Combotree ',
Fieldlabel: ' Department name ',
Name: ' DeptID ',
Hiddenname: ' DeptID ',
Allowblank:false,
width:235,
Tree:new Ext.tree.TreePanel ({
Root: {
Expanded:true,
ID: ' Root '
},
Loader:new Ext.tree.TreeLoader ({
Dataurl: ' Dept/getdeptlist '
}),
Animate:true,
Enabledd:true,
Autoscroll:true,
height:400,
Rootvisible:true
}),
Listeners: {
Select:function (Combotree) {
}
},
Scope:this
}

Backstage, controller code

/**
* Find a departmental tree with check
*
* @return
*/
@RequestMapping (value= "/getdeptlist", method = Requestmethod.post)
@ResponseBody
Public list<tree> getdeptlist () {
criteria = new criteria ();
return gradecourseservice.getdeptlist (criteria);
}

DAO Layer Code:

/**
*
* Method Description: Query department
* @param criteria
* @return list<dept> Collection
*/
List<dept> getdeptlist (criteria);

DAO corresponds to the Mapper query code:

<!--Inquiry Student Department--
<select id= "getdeptlist" parametertype= "Criteria" resultmap= "Depetmap" >
Select
a.dept_id DeptID,
A.dept_name Deptname,
A.leaf Leaf,
b.dept_id Deptpartpid,
B.dept_name Deptpartname
From spauth.base_dept a,spauth.base_dept b
where
A.dept_type = ' 2 '
and

a.dept_id = B.dept_pid
Order
by a.dept_id ASC,
b.dept_id ASC
</select>
<!--leaf Models--
<resultmap type= "cn.edu.hbcf.privilege.pojo.Dept" id= "Depetmap" >
<id property= "DeptID" column= "DeptID"/>
<result property= "Deptname" column= "Deptname"/>
<result property= "leaf" column= "leaf"/>
<collection property= "Children" oftype= "cn.edu.hbcf.privilege.pojo.Dept" >
<id property= "DeptID" column= "Deptpartpid"/>
<result property= "Deptname" column= "Deptpartname"/>
</collection>
</resultMap>

Service Layer Code:

/**
* Get a list of department drop-down boxes
* @return
*/
List<tree> getdeptlist (criteria);

Service Layer Implementation Class code:

Public list<tree> Getdeptlist (criteria) {
list<tree> resulttree = new arraylist<tree> ();
Tree treeNode = null;
list<dept> deptlist = gradecoursemapper.getdeptlist (criteria);
Dept Dept = null;
for (iterator<dept> it = Deptlist.iterator (); It.hasnext ();) {
TreeNode = new Tree ();
List<tree> childtree =new arraylist<tree> ();
Tree childnode = null;
Dept childept = null;
Dept = It.next ();
if (Dept.getdeptname (). Equals ("Hebei Finance Institute")) {
Continue;
}
Treenode.settext (Dept.getdeptname ());
Treenode.setid (Dept.getdeptid ());
for (iterator<dept> iter = Dept.getchildren (). Iterator (); Iter.hasnext ();) {
Childnode = new Tree ();
Childept = Iter.next ();
Childnode.settext (Childept.getdeptname ());
Childnode.setid (Childept.getdeptid ());
Childnode.setleaf (TRUE);
Childtree.add (Childnode);
Treenode.setchildren (Childtree);
}
if (Treenode.getchildren (). Size () ==0) {//This is the judgment that the node is not a child node. If not, let the system become a leaf node.
Treenode.setleaf (TRUE);//becomes a leaf node.
//            }
Resulttree.add (TreeNode);
}
return resulttree;
}

Tree entity Class Code:

Package cn.edu.hbcf.common.vo;

Import java.util.List;

/**
* Ext Tree Menu
*
* @author Lipenghui
* @date 2012-02-24 19:06:00
*
*/
public class Tree {

Private String ID;
private String name;
private String text;
Private String iconcls;
Private Boolean expanded;
Private Boolean leaf;
Private String URL;
Private list<tree> children;

Public String getId () {
return ID;
}

public void SetId (String id) {
This.id = ID;
}


Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

Public String GetText () {
return text;
}

public void SetText (String text) {
This.text = text;
}

Public String Geticoncls () {
return iconcls;
}

public void Seticoncls (String iconcls) {
This.iconcls = Iconcls;
}

public Boolean getexpanded () {
return expanded;
}

public void Setexpanded (Boolean expanded) {
this.expanded = expanded;
}

public Boolean getleaf () {
return leaf;
}

public void Setleaf (Boolean leaf) {
This.leaf = leaf;
}

Public String GetUrl () {
return URL;
}

public void SetUrl (String URL) {
This.url = URL;
}

Public list<tree> GetChildren () {
return children;
}

public void Setchildren (list<tree> children) {
This.children = children;
}

}

Dept Entity Class Code:

Package Cn.edu.hbcf.privilege.pojo;

Import java.io.Serializable;
Import java.util.List;
/**
* Department
* @author Zhang Zhouhai
*/
public class Dept implements serializable{

/** Department ID */
Private String DeptID;
/** Parent Department */
Private Dept parent;
/** Department Name * *
Private String Deptname;
/** Department Profile * *
Private String deptcomment;
/** is the root node 0 No 1 has */
private int leaf;

/**
* Display order
*/
Private Integer DisplayIndex;

/**
* is the number of the department
*/
Private Integer Depttype;


Private list<dept> children;


Public String Getdeptid () {
return deptid;
}

public void Setdeptid (String deptid) {
This.deptid = DeptID;
}

Public String Getdeptname () {
return deptname;
}

public void Setdeptname (String deptname) {
This.deptname = Deptname;
}

Public String getdeptcomment () {
return deptcomment;
}

public void Setdeptcomment (String deptcomment) {
This.deptcomment = deptcomment;
}

public int getleaf () {
return leaf;
}

public void setleaf (int leaf) {
This.leaf = leaf;
}

public void SetParent (Dept parent) {
This.parent = parent;
}

Public Dept getParent () {
return parent;
}


/**
* @return The Children
*/
Public list<dept> GetChildren () {
return children;
}

/**
* @param children the children to set
*/
public void Setchildren (list<dept> children) {
This.children = children;
}

/**
* @return The DisplayIndex
*/
Public Integer Getdisplayindex () {
return displayindex;
}

/**
* @param displayindex the DisplayIndex to set
*/
public void Setdisplayindex (Integer displayindex) {
This.displayindex = DisplayIndex;
}

/**
* @return The Depttype
*/
Public Integer Getdepttype () {
return depttype;
}

/**
* @param depttype the Depttype to set
*/
public void Setdepttype (Integer depttype) {
This.depttype = Depttype;
}

}

ExtJS, the realization of the tree-shaped structure of the summary

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.