EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: ClSoft on March 06, 2013, 08:22:46 AM



Title: Get all tree nodes
Post by: ClSoft on March 06, 2013, 08:22:46 AM
Hi all
after DragDrop, I need to read all Tree nodes because I need to write them into database (so I can display it again).
Here is my try:

  function    onDropVrsta(targetNode,source,point)
  {
  var roots = $('#boq_vrste').tree('getRoots');  // because it can be more roots
  for(var i = 0; i < roots.length; i++){
      alert(roots.id);  // here I have root id for each root node
    }

I need to somehow read all other nodes (for each root) and if possible, read ID and ParentID
How to do that?
Thanks.


Title: Re: Get all tree nodes
Post by: ClSoft on March 06, 2013, 11:12:05 AM
I know all children ID's but that's all:

    var children = $('#boq_vrste').tree('getChildren');
    for(var c = 0; c < children.length; c++){
      alert(children[c].id);
    }

but how to find parent id from current node?
Thanks a lot!
 


Title: Re: Get all tree nodes
Post by: stworthy on March 06, 2013, 06:55:45 PM
Please call 'getParent' method to get a node's parent node.


Title: Re: Get all tree nodes
Post by: ClSoft on March 06, 2013, 11:44:50 PM
Hi
I try that already, but don't know how to use it.
This is what I try:

    var children = $('#boq_vrste').tree('getChildren');
    for(var c = 0; c < children.length; c++){
      var nodeID = children[c].id;
      var pnode = $('#boq_vrste').tree('getParent',nodeID.target);
      alert(pnode.text);

and
      var pnode = $('#boq_vrste').tree('getParent',nodeID);
      alert(pnode);

etc..
thanks.


Title: Re: Get all tree nodes
Post by: ClSoft on March 07, 2013, 10:46:04 AM
stworthy, please?


Title: Re: Get all tree nodes
Post by: stworthy on March 07, 2013, 06:26:15 PM
Try the following code:
Code:
var t = $('#boq_vrste');
var children = t.tree('getChildren');
for(var i=0; i<children.length; i++){
var node = children[i];
var pnode = t.tree('getParent', node.target);
if (pnode){
console.log(node.text + '->' + pnode.text);
}
}


Title: Re: Get all tree nodes
Post by: ClSoft on March 08, 2013, 12:23:11 AM
Thanks stworthy, it works perfect.  :D