Jquery Easyui Combotree Expand all parent nodes according to the selected values
Jquery Easyui Combotree Expand the parent node,
Jquery Easyui Combotree expands all previous parent nodes according to the values selected by the child nodes.
Jquery Easyui Combotree Gets the selected value
================================
? Copyright Sweet Potato Yiu May 7, 2018
http://www.cnblogs.com/fanshuyao/
First, Combotree gets the parent node method GetParent, which is actually inherited from the tree plugin
JS Code
- Name Parameter Description
- GetParent Target Get The parent node,
- The target parameter indicate the node DOM object.
Tree gets the parent node:
JS Code
- $ ("#treeId"). Tree ("getParent", node.target);
Combotree Get parent node:
Java code
- var treeobj = $ ("#combotreeId"). Combotree ("tree"); Get the Combotree Tree object first
- var parentnode = Treeobj.tree ("GetParent", node.target);
Second, Combotree gets the selected value
Java code
- var treeobj = $ ("#combotreeId"). Combotree ("tree"); Get the Combotree Tree object first
- var nodeschecked = Treeobj.tree ("getchecked"); The tree object gets all the selected values of the tree, and there may be multiple
Third, expand parent node
JS Code
- $ ("#treeId"). Tree ("expand", Node.target); node is usually the parent
Iv. Expand all parent nodes based on the values selected by the leaf node
Expand methods for all parent nodes (recursively expand parent node):
JS Code
- /**
- * Expand all parent nodes according to leaf node
- * @param treeobj Tree object, (Combotree tree object gets: var treeobj = comboobj.combotree ("tree");)
- * @param node leaf nodes
- */
- 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:
JS Code
- $ ("#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 the click of text can also be checked
- return false;
- },
- Onbeforecheck: Function (node, checked) {
- if (checked) {//If it is a tick, clear the previously selected node (not 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 Sweet Potato Yiu May 7, 2018
http://www.cnblogs.com/fanshuyao/
Jquery Easyui Combotree Expand all parent nodes according to the selected values