Jquery EasyUI Combotree expands the parent node,
Jquery EasyUI Combotree expands all the previous parent nodes according to the value selected by the child node,
Jquery EasyUI Combotree get selected value
================================
©Copyright Sweet Potato Yao May 7, 2018
http://fanshuyao.iteye.com/
1. The method getParent of Combotree gets the parent node, which is actually inherited from the tree plugin
Name Parameter Description getParent target Get the parent node, the target parameter indicate the node DOM object.
Tree gets the parent node:
$("#treeId").tree("getParent", node.target);
Combotree gets the parent node:
var treeObj = $("#combotreeId").combotree("tree");//Get the tree object of combotree first var parentNode = treeObj.tree("getParent", node.target);
2. Combotree gets the selected value
var treeObj = $("#combotreeId").combotree("tree");//Get the tree object of combotree first var nodesChecked = treeObj.tree("getChecked");//Get all the selected values of the tree through the tree object, there may be multiple
3. Expand the parent node
$("#treeId").tree("expand", node.target);//node is usually the parent node
4. Expand all parent nodes according to the value selected by the leaf node
Method to expand all parent nodes (recursively expand parent nodes):
/** * Expand all parent nodes according to leaf nodes * @param treeObj tree object, (combotree tree object acquisition: var treeObj = comboObj.combotree("tree");) * @param node leaf node */ function expandParent(treeObj, node){ var parentNode = treeObj.tree("getParent", node.target); if(parentNode != null && parentNode != "undefined"){ treeObj.tree("expand", parentNode.target); expandParent(treeObj, parentNode); } };
The specific use is as follows:
$("#cmm_code_id").combotree({ multiple: true, required : true, checkbox : true, onlyLeafCheck : true,//Only leaf nodes can be checked url : "${pageContext.request.contextPath}/xxx", onBeforeSelect : function(node){ $(this).tree("check", node.target);//Control can also check when clicking on text return false; }, onBeforeCheck : function(node, checked){ if(checked){//如果是勾选操作,则把之前选中的节点清除(不勾选) var nodes = $(this).tree("getChecked"); if(nodes.length > 0){ for(var i=0; i<nodes.length; i++){ $(this).tree("uncheck", nodes[i].target); } } } }, onLoadSuccess : function(node, data){ var cmm_code_id_value = "${buildingNaming.cmm_code_id}"; if(cmm_code_id_value != null && $.trim(cmm_code_id_value) != ""){ var comboObj = $("#cmm_code_id"); var treeObj = comboObj.combotree("tree"); comboObj.combotree("setValue", cmm_code_id_value); var nodesChecked = treeObj.tree("getChecked"); if(nodesChecked.length > 0){ for(var i=0; i<nodesChecked.length; i++){ expandParent(treeObj, nodesChecked[i]); } } } } });
================================
©Copyright 蕃薯耀 2018年5月7日
http://fanshuyao.iteye.com/