4 Replies Latest reply on Aug 20, 2007 7:20 PM by ntsiii

    Mx Repeater and grid

      Can someone let me know why I keep getting the error, error: repeater is not executing.. Below is my code.

      <mx:Repeater id="r" dataProvider="{userColumnsListObject}">
      <mx:Label text="{strategyGrid.selectedItem[r.currentItem.name].toString()}"/>

      </mx:Repeater>
        • 1. Re: Mx Repeater and grid
          ntsiii Level 3
          "currentItem" ONLY exists when the Repeater is rendering the child elements. You can't use it in event handler specifications

          I think the label text binding expression you are attempting is illegal, since it is trying to set up an ongoing binding expression using currentItem. Binding is actually setting up an event strucure behind the scenes, so currentItem is not valid.

          You need to use r.getRepeaterItem(), like this:
          ="{strategyGrid.selectedItem[r.getRepeaterItem().name].toString()}"/

          When working with Repeater, especially if it gets a bit more complex than what you have, you willsave yourself a lot of grief if you use a custom component. Below is some sample code.

          Tracy

          When working with Repeater, I advise creating a custom component that you will repeat, and pass it the entire "currentItem", In the component, implement a "setter" function to receive the currentItem data.

          Now, in the component, you can code normally, binding to the data as you wish, without the hard to read currentItem references. You also avoid the binding warnings without the cast/conversion because the binding source is a true XML object.

          And, you can dispatch events normally. In the event handler, you can reference the component via the event.target property, and thus get a direct reference to the dataProvider item. This is easier to write and read than having to use getRepeaterItem().

          Here are some code snippets:

          In the main app or component (note how "clean" and readable this is):
          <mx:Application
          <mx:VBox ...>
          <mx:Repeater id="rp" dataProvider="{_xmlData}" ...>
          <mycomp:MyRepeatedComponent xmlItem="{rp.currentItem}" .../>
          </mx:Repeater
          </mx:VBox>

          And in the component, MyRepeatedComponent.mxml:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:HBox ...
          <mx:Script><![CDATA[
          [Bindable]private var _xmlItem:XML;

          public function set xmlData(xml:XML):void
          {
          _xmlItem = xml;
          //do any special, non-bound ui stuff you want
          }//
          ]]></mx:Script>
          <!-- Now declare the Item UI -->
          <mx:Text id="lbDescription" text="{_xmlItem.@description}" width="100%" height="100%" />




          1 person found this helpful
          • 2. Mx Repeater and grid
            Tracy,
            This code is not working..

            ="{strategyGrid.selectedItem[r.getRepeaterItem().name].toString()}"/


            However, if I change the.name to an actual name of the column it will work. Basically I dont think the [r.getRepeaterItem().name] is evaluating to the dynamic variable name... Any help from anyone would be greatly appreciated :)


            • 3. Re: Mx Repeater and grid
              If anyone could help me out on this i would greatly appreciate it :)
              • 4. Re: Mx Repeater and grid
                ntsiii Level 3
                Use a custom component, so you can get rid of currentItem, getRepeaterItem, and can debug the data .

                Tracy
                1 person found this helpful