![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
I found examples of this but I'm having a hard time figuring out why it does
not work. Here's my code..Any help appreciated. My function; private function expandTreeNodes():void{ var projectParts:XML = treLinks.dataProvider[0]; treLinks.openItems = projectParts..node; /* I even tried the code below to no avail ** for each (var item:XML in projectParts..node){ ** treLinks.expandItem(item, true); ** } */ } My dataprovider for the tree; <mx:XMLListCollection id="projectParts"> <mx:XMLList> <node label="Product" data="100"> <node label="Part A" data="70"/> <node label="Part B" data="10"> <node label="Component a" data="2"/> <node label="Component b" data="3"/> <node label="Component c" data="0" isBranch="true" /> <node label="Component d" data="5" /> </node> <node label="Part C" data="15"/> <node label="Part D" data="5"/> </node> </mx:XMLList> </mx:XMLListCollection> My Tree: <mx:Tree id="treLinks" x="10" y="10" width="680" height="298" fontSize="10" labelField="@label" dataProvider="{projectParts}" creationComplete="expandTreeNodes()" /> |
| Sponsored Links |
|
|||
|
Hi,
Firstly the error you were getting is because you cant apply all that you apply on XML object to XMLListCollection. In order to do it you need to iterate over all XML objects in the XMLListCollection and then apply.Hope you got it. Here is the working code attached. Any doubts do reply. private function expandTreeNodes():void{ for each(var item in projectParts){ treLinks.openItems = item.node; } } |
|
|||
|
Hey guys,
FrankieG813, if you are just trying to expand all of your tree branches and their children when the app first loads, do this: private function expandTreeNodes():void{ treLinks.expandChildrenOf(projectParts[0],true); } You don't use openItems to expand tree branches, you use either expandChildrenOf() or expandItem(). Since you really only have one top-level node, I just used expandChildrenOf() on that, and all its children open up. |
|
|||
|
Thanks so much for your help. FYI, I first tried GallaHarsha's change and it
did not work. It also gave me a warning about item not having a declaration. I tried rtalton's solution and it works. My next question would be how would I handle this if there were multiple top level nodes. Thanks Frank |
|
|||
|
Just wanted to clarify: gallaharsha's solution should work but I have better
results with this way... didn't mean any offense to gallaharsha. Try this to open multiple tree branches. It uses a for loop and goes to each top-level node and calls expandChildrenOf(). Look below for the XML I'm using (it's based on yours, but with one more node appended to it). Be sure you read the help docs for more detail on the Tree control: http://livedocs.adobe.com/flex/3/lan...ee.html&mx/con trols/class-list.html private function expandTreeNodes():void{ //treLinks.expandChildrenOf(projectParts[0],true);//WORKS FOR A SINGLE NODE ONLY. for (var i:int = 0; i < treLinks.dataProvider.length; ++i){ treLinks.expandChildrenOf(projectParts[i],true) } } <mx:XMLListCollection id="projectParts"> <mx:XMLList > <node label="Product" data="100"> <node label="Part A" data="70"/> <node label="Part B" data="10"> <node label="Component a" data="2"/> <node label="Component b" data="3"/> <node label="Component c" data="0" isBranch="true" /> <node label="Component d" data="5" /> </node> <node label="Part C" data="15"/> <node label="Part D" data="5"/> </node> <node label="Suppliers" data="100"> <node label="ACME Fireworks" data="70"/> <node label="Wily Coyote Bomb Parts" data="70"/> <node label="Road Runner Shoe Supply" data="70"/> </node> </mx:XMLList> </mx:XMLListCollection> |
|
|||
|
No offense meant towards gallaharsha either. I just wanted to alert him/her
that there were compilation errors and what was suggested did not work. I really do appreciate any suggestions. I tried your solution for the single node and it worked, however when I tried to implement the multi node solution it did not work. When I un-remarked the line that says WORKS FOR SINGLE NODE ONLY, sure enough, it expanded the nodes, but only on the first node. Now I'm confused. |
|
|||
|
The code got posted incorrectly, sorry.
Change this line: treLinks.expandChildrenOf(projectParts,true) To: treLinks.expandChildrenOf(projectParts[i],true) The "[i]" is a reference inside the loop to the node# being operated upon. In each loop, "i" increments (0,1,2,3,etc). So you can read this line as in treLinks, expand all the children of node #1 in projectParts. Look up the expandChildrenOf() method and make sure you understand what's going on. This will help you when you're debugging you app. Have fun! |
|
|||
|
Sorry, but I don't see any changes to this line other than the fact that true
is italicized on the post. Below is what I see.... Change this line: treLinks.expandChildrenOf(projectParts,true) To: treLinks.expandChildrenOf(projectParts,true) |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise