You don't need recursion.  The following example actually expands the
nodes, but could just as well build a list.

Tracy

  //starts at the given node, walks up the tree opening nodes as it goes
  private function expandParents(xmlNode:XML):void
  {
    while (xmlNode.parent() != null) {  
      xmlNode = xmlNode.parent();
      myTree.expandItem(xmlNode,true, false);
    }
  }//expandParents

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Carpenter, Steven
Sent: Monday, March 31, 2008 12:03 PM
To: [email protected]
Subject: [flexcoders] Recursing Up a Tree

 

Hi all,

I'm still learning with Flex, and I'm stuck on this problem:

I have a Tree component and for any given selectedItem, I need to get a
list of parent nodes for that item - I'm not concerned with the children
of each parent, I just need to get a list or path of parent nodes for an
item, back up to the root node. I got as far as creating a method that
will take the selected item and get its parent node using
Tree.getParentItem(node) and ITreeDataDescriptor.isBranch() but I'm
struggling with building a recursive function that will let me walk back
up the tree. I've seen a great example of walking down a tree's
DataDescriptor using IViewCursor but not I'm stuck on creating something
that works in the other direction. Does anyone have any pointers/advice?
Thanks in advance!

 

Reply via email to