This is a migrated thread and some comments may be shown as answers.

Recursing up tree

3 Answers 42 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 19 Nov 2008, 12:08 AM
When a child is unchecked, I need to recurse up the tree and uncheck the parents.  For some reason when I say parentNode = node.get_parent()  I can not call not then call parentNode.set_checked();  This seems very odd.  I am using a javascript debugger and it seems as though the get_parent() method disapears after the assignment to parentNode. 

Please help. 

This is the heart of what I have now (which is not working).

parentNode = node.get_parent();

 

while (parentNode != null)

 

{

    parentNode.set_checked(

false);  //error thrown here set_checked method not found.

 

    parentNode = parentNode.get_parent();
}



Thanks,
Ken

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Nov 2008, 08:08 AM
Hi Ken,

Try the following code snippet to achieve the desired sceanrio.

JS:
<script type="text/javascript" > 
function OnClientNodeChecking(sender, eventArgs) 
 
if(eventArgs != null) 
   var node = eventArgs.get_node();  
     
  if(node.get_checked(false)) 
  { 
  
    var Parentnode = node.get_parent();  
    var lastnode
      while (Parentnode != null &&last.get_level() != 0) 
       {      
          Parentnode.set_checked(false); 
          last = Parentnode
          Parentnode=Parentnode.get_parent(); 
           
       } 
   } 
  } 
<script/> 


Thanks
Shinu.
0
Ken
Top achievements
Rank 1
answered on 19 Nov 2008, 02:39 PM
Thanks this is working (except for the duplication typo ParentnodeParentnode)

My code didn't have last.get_level()  Was this the problem?  What's this method all about?
0
Shinu
Top achievements
Rank 2
answered on 20 Nov 2008, 06:32 AM
Hi Ken,

The above described scenario is all about unchecking the parent nodes on unchecking its child node. For this we need to loop through the corresponding parent nodes of an unchecked child node. While doing so the last node's(which is the root node) parent is RadTreeView itself which is not having the CheckBox attribute so the set_checked() method will cause error. To prevent this error we are eliminating the last node from the loop using the get_level()  method.

Shinu
Tags
TreeView
Asked by
Ken
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ken
Top achievements
Rank 1
Share this question
or