thanks. I think the ArrayCollection is the key. Using addItem
instead of push makes all the difference. It now works.
- Kevin
On Mar 24, 2007, at 6:04 PM, Jeffry Houser wrote:
I've done this with an ArrayCollections, but never with an Array.
The code would be something like this:
<mx:Script>
<![CDATA[
public var myArray:Array = ['test1','test2','test3'];
public var myArrayCollection = new ArrayCollection(myArray);
public function addItem():void{
myArrayCollection.addItem('test4');
}
]]>
</mx:Script>
<mx:VBox>
<mx:Repeater id="rp" dataProvider="{myArrayCollection}" >
<mx:TextInput id="myRepeat" />
</mx:Repeater>
<mx:Button label="click me" click="addItem();" />
</mx:VBox>
A few caveats...
a) I didn't test this code
b) In my situation, I wasn't adding from the same component that
was displaying things, so the 'add' and 'display were never shown
at the same time. There could have been other code that made the
refresh work, but I don't remember anything explicit.
c) When accessing a repeater element you use currentIndex when it
is repeating, but repeaterIndex after the fact. I haven't found a
simple way to switch between the two of them, but my solution was
something like this:
try{
return myArrayCollection.getItemAt(loop.currentIndex );
}
catch (e:Error){
return myArrayCollection.getItemAt(loop.repeaterIndex );
}
I imagine there must be a better way
At 05:35 PM 3/24/2007, you wrote:
here is a little test to illustrate what I am trying to do (except
it doesn't work.) I was hoping that updating the dataProvider
would add another item to the repeater...
<mx:Script>
<![CDATA[
public var myArray:Array = ['test1','test2' ,'test3'];
public function addItem():void{
myArray.push('test4');
}
]]>
</mx:Script>
<mx:VBox>
<mx:Repeater id="rp" dataProvider="{ myArray}" >
<mx:TextInput id="myRepeat" />
</mx:Repeater>
<mx:Button label="click me" click="addItem();" />
</mx:VBox>
On Mar 24, 2007, at 5:16 PM, Kevin wrote:
I have a repeater (adding TextInput fields) that is bound to an
ArrayCollection on my model. I was hoping that essentially I could
add a row by just pushing a value into my ArrayCollection on the
model. However, this isn't working. I assume I need to also
"refresh" the repeater, but can't seem to figure out the best way to
do that.
Thanks, Kevin
--
Jeffry Houser, Software Developer, Writer, Songwriter, Recording
Engineer
AIM: Reboog711 | Phone: 1-203-379-0773
--
My Company: < http://www.dot-com-it.com>
My Podcast: < http://www.theflexshow.com>
My Blog: < http://www.jeffryhouser.com>
Connecticut Macromedia User Group: < http://www.ctmug.com>