EasyUI Forum
April 29, 2024, 10:28:09 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: tree getChildren blocks my code  (Read 12158 times)
forum6691
Newbie
*
Posts: 39


View Profile
« on: May 09, 2014, 01:24:14 PM »

I have a code with a treeview with some objects inside.
When I want to know If a node has some child, with this code
 
function requeteNoeud(node)
 {
  
  var childNodes=J('#treev').tree('getChildren',node.target);
  if(childNodes.length >0) alert("some children");


my code blocks on the first line of the function and I have this error

TypeError: data is undefined

for(var i=0;i<data.length;i++){

jquery....min.js (ligne 1907)

The code in jquery is:
function _108(data,_163){
var _164=[];
for(var i=0;i<data.length;i++){
_164.push(data);
}
and the line in error is: for(var i=0;i<data.length;i++){

Is someone could help me ?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 09, 2014, 05:59:36 PM »

To detect if a node has some children nodes, simply call 'isLeaf' method. Returning true indicate that the node is a leaf node and has no sub nodes.
Code:
var isLeaf = $('#tt').tree('isLeaf', node.target);
console.log(ifLeaf);
Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #2 on: May 09, 2014, 09:16:52 PM »

Ok sworthy, but I want to detect subdirectory in my tree and isLeaf method gives me FALSE even if I have subdirectories in my tree.
I 'm looking for a test to detect all type of children (directories or leaves) in my tree .
Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #3 on: May 11, 2014, 07:04:33 AM »

Hi sworthy.

I tried
Code:
var isLeaf = $('#tt').tree('isLeaf', node.target);

It gives to me a "false value" all the time even if the node has children ! I think it's normal because , all my nodes are folders and not leaf (at this time).

I explain my problem again, because I think you don't understand it the first time.
I want to modelize in a tree some REGATE (first level of folder) which contains some GROUP (second level of folder) which contain some CONTACT (third level of folder) which contain some GPSPOINTS( leaves at the fourfth level).

As I can have a lot of objects to show in my tree, I load data only for the branch user selects it one level by one level.

Initialy, I have a empty tree. I load by an ajax request the REGATE as first folder (but not these sub contents).
When then I click to expand a folder REGATE, I execute an other ajax request to load the content (the GROUPS) et show it (but not these sub contents).
When I click to expand a folder GROUP,  I execute an other ajax request to load the content (the CONTACTS) et show it (but not these sub contents).
And to finish , when I click to expand a folder CONTACT,  I execute an other ajax request to load the content (GPSPOINTS) as leaves.

So when I select a level of the tree, I have to know if the data is already loaded or not to forbide two identical loads. And I think that the method to know if the node has a child folder ou children folder is the good.

Sorry for the long explain, but maybe it's clearly for you Sworty ?
Finally how to determine if a folder node has folder children ?

Thanks.
Cyril
« Last Edit: May 11, 2014, 07:46:28 AM by forum6691 » Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #4 on: May 11, 2014, 08:01:14 AM »

Finally, I adapt this answer http://www.jeasyui.com/forum/index.php?topic=1951.msg4306;topicseen#msg4306
to determine if I have or not sub folder at a level of my tree.

I don't change the extend function but I change the code after the call method
Code:
var folders = J('#treev').tree('getFolders', node.target);
 
 if(folders.length ==0) // if 0 then there isn't any subfolders for this node
 {
...
 }

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: May 11, 2014, 09:12:58 AM »

As you mentioned, your tree has 4 levels. Each level indicates different content. So another solution to solve your issue is to let the server return the additional information indicating if a node has sub nodes. You can call 'getNode' method to retrieve this additional property.
Code:
var n = $('#tt').tree('getNode', node.target)
console.log(n.hasChild);  // the hasChild property returned from server
« Last Edit: May 11, 2014, 09:18:27 AM by stworthy » Logged
forum6691
Newbie
*
Posts: 39


View Profile
« Reply #6 on: May 11, 2014, 09:55:11 AM »

Thanks sworty to answer me on sunday !

I tried hasNode method on the selected node but it doesn't give me any value, neither 0 or false, neither true or a value, so I prefer use the method with getfolders which is OK in my code.
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!