When easyui expands the tree by default, it clicks the black triangle on the front of the node. In this way, operations are not human-friendly. In actual use, the presence of old computers and the vertigo of older users are often inaccurate; to expand a node by clicking the node name, you must add a method to expand the node to the expand event.
Add in onselect event
Certificate (this).tree('expand', node.tar get );
When the node is selected, expand the node under the node. This method only expands the next level node, and does not expand the nodes under the child node.
To expand all nodes:
Certificate (this).tree('expandall', node.tar get );
$(document).ready(function(){$('#dept').layout();$('#deptTree').tree({checkbox:false,url:'loadDeptJson.action?node=-1',onBeforeExpand:function(node,param){$('#deptTree').tree('options').url="loadDeptJson.action?node="+node.id;},onSelect:function(node){$('#deptContent').load("viewDepartment.action?department.id="+node.id);$(this).tree('expand',node.target);},});});
Bind multiple events to onclick. If a department has a person, the person is displayed in the grid. If a sub-department has a sub-department, the solution of the sub-department is displayed:
$ ("# Dept_tree"). Tree ({URL: "Servlet/searchservlet? Dispatch = 2 & unit_id = "+ unit_id +" & id = 0 ", // The URL here is the loading tree onbeforeexpand: function (node, Param) {$ ("# dept_tree "). tree ("options "). url = "Servlet/searchservlet? Dispatch = 2 & unit_id = "+ unit_id +" & id = "+ node. ID;}, onselect: function (node) {$ (this ). tree ("Expand", node.tar get); // expand the subnode of the clicked text },});
Onclick: function (node) {// alert ("ID" + node. ID + "department ID:" + node. attributes. department_id + "-- unit --" + node. attributes. unit_id); var url22 = "Servlet/searchservlet? Dispatch = 22 & unit_id = "+ node. attributes. unit_id; $. getjson (url22, {department_id: node. attributes. department_id}, function (data) {If (data. length = 0) {var url = "Servlet/searchservlet? Dispatch = 3 & department_id = "+ node. attributes. department_id; $ ("# person_grid "). dataGrid ({URL: URL, toolbar: results_grid_default_toolbar, columns: results_grid_default_columns })}});},
Easyui tree click the text to expand the node