EasyUI Forum
September 14, 2025, 07:25:02 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: Question - Availability of "target" property/DOM node of children in tree  (Read 8944 times)
davistom
Newbie
*
Posts: 10


View Profile Email
« on: May 25, 2015, 07:00:09 AM »

I am trying to implement some recursive behavior in an essyui tree while using the built in asynchronous loading mode. The overall purpose of the desired behavior is to control visibility of map features of a separate, non-easyui javascript object - a google map. Almost everything I am attempting to implement works as I expect, but I have one niggling problem. The problem reduces to the availability of the "target" property of the children of nested folder nodes when trying to recursively expand a tree branch. Following is a description of the implementation, expected behavior, observed behavior and some key debugging observations, with a concluding question.

I implement a tree using asynchronous loading from a hierarchical node data set with nested folders. The tree is initialized with check boxes which control the visibility of map features in a companion google map. If a folder is checked (or expanded while checked), subordinate folders should be expanded (to force loading) and checked. This is implemented by looping through and recursively expanding children, using the "expand" method with [child].target as parameter, in an OnExpand handler.  The problem is that when a folder which includes a mix of leaf nodes and multiple folder child nodes is expanded, only the first child folder gets expanded. Careful debugging reveals that only the first child folder has an assigned "target" property, so the "expand" attempt on the first child folder works as expected, but on the second and subsequent folder children it does nothing.

Question - On folder expansion/node data loading, when/how does the "target" property get assigned, or more to the point, when/how does the "target" property and associated DOM node become available to user code?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: May 25, 2015, 07:11:16 PM »

The 'onExapnd' event handler takes 'node' parameter value, which indicates the expanding node. If you want to retrieve the node data with 'target' property, please call 'getData' method instead.
Code:
$('#tt').tree({
onExpand: function(node){
var data = $(this).tree('getData', node.target);
console.log(data)
}
})
Logged
davistom
Newbie
*
Posts: 10


View Profile Email
« Reply #2 on: May 26, 2015, 06:01:32 AM »

I don't think using the 'getData' method on the expanding node solves my problem. The problem appears to me to be that the children of the expanding node do not all have their 'target' property assigned, at least not when the 'onExpand' handler gets invoked. I have carefully examined/verified this via debugging using Chrome developer tools. In fact, the observed behavior when the 'onExpand' handler is invoked is that the first child has its 'target' property set properly but the second and all subsequent children have no assigned 'target' property. The result is that the first child, which as it happens is a folder, gets expanded recursively as expected but no subsequent folder nodes in the children list do.

Following is a code snippet representing the 'onExpand' handler with which the tree is initialized and a more detailed description of the node set and observed behavior -

onExpand: function(node){
   console.log(node.text);
   for(var i=0; i<node.children.length; i++){
       $('#places_tree').tree('expand', node.children.target);
        }
},                  }

The node being expanded is a folder node with 53 child nodes, eight of which are folders with children and 45 of which are leaf nodes. As it happens, the first of the 53 children is a folder containing 6 leaf node children, and the remaining seven folders are scattered throughout the 53 children list. When the state is trapped in the 'onExpand' handler, the first child node has its 'target' property assigned correctly but none of the other 52 children have a 'target' property assigned. The result of continuing execution is that the first child folder is expanded as expected but none of the remaining seven folders gets expanded, presumably because the 'node.children.target' parameter passed in the 'expand' method invocation loop is undefined for all but the first loop iteration.

Hopefully, this clarifies the issue. An alternative clarification may be the question - How can one recursively expand a folder and all of its descendants?
Logged
davistom
Newbie
*
Posts: 10


View Profile Email
« Reply #3 on: May 26, 2015, 06:17:05 AM »

Please ignore my reply above. Based upon the previous reply by jarry, I have managed to sort it out. Sorry for jumping off too early.
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!