One approach I have considered is this: on getting the tree data, build an associative array that uses an id as a key and contains a reference to the node. That way you would have random access to any node using the id. You would take a performance hit up front building the associative array, but thereafter retrieving a node would be much faster from the hashed list than by recursing all nodes and comparing the id.
To record a tree's state when a node opens, you would start with the just opened node and put it in the state array, and then climb up the tree, one parent at a time. If any parent node exists in the state array(use an associative array here too), remove it. This way, for any path of open nodes, you will only have one recorded node, the last one in the chain.
To restore a tree's state, you would do a for..in loop over the state array, and for each recorded node id, find the actual node reference in the random access array/map. Then climb the tree by parent, opening nodes as you go.
I may try to do an example of this.
Tracy
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of moyosaned
Sent: Thursday, June 01, 2006 5:08 PM
To: [email protected]
Subject: [flexcoders] Re: Flex 1.5 Maintaining tree node state after dataprovider refresh
public function recurseAndOpen(x:XML, tree:Object){
for(var each in x.childNodes){
if(x.childNodes[each].attributes.isOpen){
var t = tree.getDisplayIndex(x.childNodes[each]);
tree.setIsOpen(tree.getNodeDisplayedAt(t), true, false, false);
}
if(x.childNodes[each] != undefined){
this.recurseAndOpen( x.childNodes[each], tree );
}
}
}
Maybe you can use this....... store --> .attributes.isOpen
every time a node opens or closes... on refresh fill the tree with new
data. and use the old structure as a lookup tree to reopen the nodes...
--- In [email protected], "Karl Johnson" <[EMAIL PROTECTED]>
wrote:
>
> I have tried many different methods without much success. I need to be
> able to maintain, or at least give the appearance to the end user that I
> have maintained, the state of the tree after a refresh of the
> dataprovider (meaning I set the dataprovider an xml result of a
> webservice every x minutes).
>
> Has anyone successfully accomplished this? I tried popluating an array
> of the indexes of all displayed nodes, and then after refresh, looping
> through the state array and calling setIsOpen and passing in
> getTreeNodeAt(indexStoredInArray), etc... But that only works with the
> top level.
>
> Any suggestions? Any help is very much appreciated.
>
> Thanks,
> Karl
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

