View Full Version : Flex Targeting with nested repeaters
nburlington
July 30th, 2008, 04:43 PM
I have two repeaters in my UI. The first displays all of the 'projects' in my collection. Each 'project' has a collection of 'images'. The projects are displayed as panels with the image list inside each panel as a set of button components.
When you click on one of the image buttons, I want to delete that image from the project. But how do I target the first repeater?
I'm using:
click="deleteImage(event.currentTarget.getRepeaterItem())" to capture the 'image' repeater, but how can i grab the 'project' repeater in the same event?
nburlington
July 31st, 2008, 05:19 PM
Let me show my code so it makes sense. I have a projectRepeater and an imageRepeater. I want to give the user the ability to click the deleteImage button and delete the current image from the current project. I can target the current image just fine with the 'event.currentTarget.getRepeaterItem()' but I can't figure out how to target the projectRepeater. I've tried 'projectRepeater.getRepeaterItem()' but that doesn't work.
<mx:Repeater id="projectRepeater">
<mx:Panel width="500" title="{projectRepeater.currentItem.name}" height="300">
<mx:VBox width="100%">
<mx:Repeater id="imageRepeater" dataProvider="{projectRepeater.currentItem.images.list}">
<mx:HBox>
<mx:LinkButton label="{imageRepeater.currentItem.name}"/ <mx:Button id="deleteButton" label="Delete" click="deleteImage(event.currentTarget.getRepeaterItem())"/>
</mx:HBox>
</mx:Repeater>
</mx:VBox>
<mx:ControlBar>
<mx:Button id="deleteProject" label="Delete Project" click="deleteProject(event.currentTarget.getRepeaterItem( ))"/>
</mx:ControlBar>
</mx:Panel>
</mx:Repeater>
earlond
August 1st, 2008, 03:20 PM
I'm very new to this myself, in fact I'm looking for an answer to a similar issue. It seems to me you wouldn't need to use getRepeaterItem. Can't you just use the repeater id to target it? As in:
click="deleteProject(projectRepeater)"
Let me show my code so it makes sense. I have a projectRepeater and an imageRepeater. I want to give the user the ability to click the deleteImage button and delete the current image from the current project. I can target the current image just fine with the 'event.currentTarget.getRepeaterItem()' but I can't figure out how to target the projectRepeater. I've tried 'projectRepeater.getRepeaterItem()' but that doesn't work.
<mx:Repeater id="projectRepeater">
<mx:Panel width="500" title="{projectRepeater.currentItem.name}" height="300">
<mx:VBox width="100%">
<mx:Repeater id="imageRepeater" dataProvider="{projectRepeater.currentItem.images.list}">
<mx:HBox>
<mx:LinkButton label="{imageRepeater.currentItem.name}"/ <mx:Button id="deleteButton" label="Delete" click="deleteImage(event.currentTarget.getRepeaterItem())"/>
</mx:HBox>
</mx:Repeater>
</mx:VBox>
<mx:ControlBar>
<mx:Button id="deleteProject" label="Delete Project" click="deleteProject(event.currentTarget.getRepeaterItem( ))"/>
</mx:ControlBar>
</mx:Panel>
</mx:Repeater>
nburlington
August 1st, 2008, 03:34 PM
in that case 'projectRepeater' references the entire Projects ArrayCollection. projectRepeater.getRepeaterItem() also doesn't work.
earlond
August 1st, 2008, 03:42 PM
This resource will explain you how to target the elements. Look for the item 'Referencing repeated components'. I hope that helps.
http://www.adobe.com/devnet/flex/quickstart/using_the_repeater/
nburlington
August 1st, 2008, 03:57 PM
That doesn't solve the problem of targeting a parent repeater in a nested situtation. You can use data from the parent repeater for 'label' and 'text' attributes etc. But when you fire an event, you can't reference the parent repeater because you no longer have access to its 'currentItem' or 'currentIndex' values.
earlond
August 1st, 2008, 06:31 PM
Yes, I see what you mean. I have no idea, sorry. Normally in actionscript I'd create a new property in the object and store an id for future reference, but Flex won't let you do that, unless you create your own custom components.
I'm going going to keep watching this post to see if anyone else has an answer.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.