I can’t figure out how to get a dataProvider from a nested ArrayCollection. I’ll try to provide as much code as possible without dumping my whole project in. If I miss something critical, let me know.
Here is the concept. Clients have Projects. Projects have Images. I want to show this relationship in a form. Displaying the list of Images for each Project is where I’m stumbling.
This is what it looks like in xml.
<data>
<client name="clientName">
<project name="project1">
<image name="image_1.jpg" />
<image name="image_2.jpg" />
<image name="image_3.jpg" />
<image name="image_4.jpg" />
</project>
<project name="project2">
<image name="image_1.jpg" />
<image name="image_2.jpg" />
</project>
</client></data>
Now, when I load the .xml in, I have custom classes for Clients, ClientList, Project, ProjectList, ImageList and I push all the xml data into that structure. Basically each of the list classes contains a ‘list:ArrayCollection’ value that contains the various items in that list as well as the functions to add and remove items in the list. The lists are what I use as dataProviders in the form.
Each Client object has a ProjectList that contains all the Projects for that Client. In turn, each Project has an ImageList that contains all the images for that project.
The populateForm below is triggered when a combobox changes. It receives the event with a client attached.
private function populateForm(event:Event):void{
//selectedClient becomes the
var selectedClient:Object = event.target.selectedItem;
/*this is easy enough. I already gave each client a name value and this displays it to the textfield in my form.*/
clientName.text == selectedClient.name;
/* this is also working. I'm using the 'list:ArrayCollection' of that client's projects as the dataprovider for the first repeater in my form */
projectRepeater.dataProvider = selectedClient.projects.list;
//imageRepeater.dataProvider = ?????
//skipping ahead to my mxml
<mx:Form>
<mx:FormItem>
<mx:VBox>
<mx:Repeater id="projectRepeater">
<mx:Panel width="500" title="{projectRepeater.currentItem.name}">
<mx:VBox width="100%">
<mx:Repeater id="imageRepeater">
<mx:List labelField="name" dataProvider="{????}"/>
</mx:Repeater>
</mx:VBox>
</mx:Panel>
</mx:Repeater>
</mx:VBox>
</mx:FormItem>
</mx:Form>
How do I set an appropriate dataProvider for the imageRepeater? The projectRepeater makes sense because I can layout all projects for each client. But the images are nested. How can I target them?