7 Replies Latest reply on Aug 1, 2008 10:32 AM by JRLeonard

    Nested Repeaters

    JRLeonard
      I have nested repeaters to display a collection of Projects where each Project can have multiple images. I'm using the projectRepeater to render a Panel for each Project. Within that each Panel, I'm rendering a linkButton and a Button(delete) for each Image. The linkButton would allow you to view the image and the delete Button allows you to remove it from that collection.

      My problem is that I don't know how to capture the projectRepeater item on the click event. When I use 'event.currentTarget.getRepeaterItem()' on the Image's delete button, it obviously references the imageRepeater. Based on the code below, what do I need to do to target the projectRepeater?
        • 1. Re: Nested Repeaters
          Gregory Lafrance Level 6
          Search for this in FB3 help:

          "Referencing nested Repeater components"

          • 2. Re: Nested Repeaters
            JRLeonard Level 1
            Thanks Greg. The problem is that that sample doesn't show how to reference the parent repeater with a click event. How do I target once I've lost the parent's currentItem reference?
            • 3. Re: Nested Repeaters
              Level 7

              "JRLeonard" <webforumsuser@macromedia.com> wrote in message
              news:g6t7d8$mhi$1@forums.macromedia.com...
              >I have nested repeaters to display a collection of Projects where each
              >Project
              > can have multiple images. I'm using the projectRepeater to render a Panel
              > for
              > each Project. Within that each Panel, I'm rendering a linkButton and a
              > Button(delete) for each Image. The linkButton would allow you to view the
              > image
              > and the delete Button allows you to remove it from that collection.
              >
              > My problem is that I don't know how to capture the projectRepeater item on
              > the
              > click event. When I use 'event.currentTarget.getRepeaterItem()' on the
              > Image's
              > delete button, it obviously references the imageRepeater. Based on the
              > code
              > below, what do I need to do to target the projectRepeater?
              >
              > <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>

              If the data source is XML, you can use the parent property.

              If not, try something like

              event.target.document.parent.repeaters[0].getRepeaterItem(n)

              The way I typically do this kind of thing is to put a break point in the
              function and drill down into the available properties until I can find the
              piece I need.

              Of course, you need to know what item it was, but if your data source is
              XML, you can use childIndex().

              HTH;

              Amy


              • 4. Re: Nested Repeaters
                Gregory Lafrance Level 6
                This seems to work:
                • 5. Re: Nested Repeaters
                  JRLeonard Level 1
                  That will work to target a UI component and remove it from the displayList. What I need is a way to target the proper arrayCollection and remove the item from that.

                  I could loop through all the Project ArrayCollections and then loop through each one's Images ArrayCollection until a certain property matched but that wouldn't allow me to reuse Images in various projects. So that's not a proper solution.
                  • 6. Re: Nested Repeaters
                    Gregory Lafrance Level 6
                    I think you need a variety of data constructs that are used to build the data construct that ultimately builds the UI. That way you can delete items from the UI dataProvider, and have mechanisms to put items back in there, from the other data constructs that are not touched by deletes.
                    • 7. Re: Nested Repeaters
                      JRLeonard Level 1
                      But I can't delete from the dataProvider unless I can target it. I'm not worried about retrieving data that has been deleted. Its not one of the functional requirements.