EasyUI Forum
July 17, 2018, 08:19:32 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Find Tree Node by Name  (Read 66 times)
don
Newbie
*
Posts: 4


View Profile
« on: July 10, 2018, 09:56:08 AM »

I'm using a simple list (ul) for the nodes of my tree. Can someone tell me how to search or find a specific node using only the list item's text? Ultimately I want to check/uncheck a checkbox node using code. So for example, if I had a checkbox tree that listed colors, I could (using code) check nodes 'red' and 'yellow'.  Huh
« Last Edit: July 11, 2018, 09:22:25 AM by don » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3295


View Profile Email
« Reply #1 on: July 11, 2018, 01:28:33 AM »

The code below shows how to find a node by 'text' and check it.
Code:
var t = $('#tt');
var mynode = null;
var roots = t.tree('getRoots');
$.easyui.forEach(roots, true, function(node){
    if (node.text == 'Java'){
        mynode = node;
        return false;
    }
});
if (mynode){
    var el = $('#'+mynode.domId);
    t.tree('check', el[0])
}
Logged
don
Newbie
*
Posts: 4


View Profile
« Reply #2 on: July 11, 2018, 07:01:16 AM »

[SOLVED] Thanks stworthy! For others and future reference, here is a function that returns a tree node's element using the node's text:
Code:
/**
*Retrieve tree node element using node list item <li> text
 *
 * @param {easyUI.Tree} tree easyUI tree object
 * @param {string} nodeText list item <li> text of desired node
 *
 * @return {element} the tree node <li> element
 */
function getNodeByText(tree, nodeText) {
var mynode = null;
var roots = tree.tree('getRoots');
$.easyui.forEach(roots, true, function (node) {
if (node.text == nodeText) {
mynode = node;
return false;
}
});
return $('#' + mynode.domId);
};
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!