Recursing up tree

4 posts, 0 answers
  1. Ken
    Ken avatar
    6 posts
    Member since:
    Jul 2008

    Posted 18 Nov 2008 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Nov 2008 Link to this post

    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.
  3. Ken
    Ken avatar
    6 posts
    Member since:
    Jul 2008

    Posted 19 Nov 2008 Link to this post

    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?
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2008 Link to this post

    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
Back to Top