Wednesday, March 12, 2008

Nested Repeaters In Flex 3 using XML

I've been working with .NET for the past few weeks (my latest excuse for not posting but thats a whole another subject...) so I've gotten attached to the idea of nested repeaters for display purposes.

I was looking for a simple example of doing the same if Flex but didn't find one so I figured I would post a little something.

It actually is very simple:

<mx:XML id="myXML" xmlns="">
<root>
<company title="Company 1" code="1">
<office name="Location 1" />
<office name="Location 2" />
<office name="Location 3" />
</company>
<company title="Company 2" code="2">
<office name="Location 1" />
<office name="Location 2" />
</company>
<company title="Company 3" code="3">
<office name="Location 1" />
<office name="Location 2" />
</company>
</root>
</mx:XML>


<mx:VBox width="100%" >

<mx:Repeater id="primaryRepeater" dataProvider="{myXML.company}">
<mx:Label text="{primaryRepeater.currentIndex} - {primaryRepeater.currentItem.@title}"/>

<mx:Repeater id="nestedRepeater" dataProvider="{myXML.company[primaryRepeater.currentIndex].office}">
<mx:Text htmlText=" -- {nestedRepeater.currentItem.@name}" width="75%"/>
</mx:Repeater>

</mx:Repeater>

</mx:VBox>

No comments: