First, don't use the names of existing properties, methods or classes
for your component, or variable names.  Specifically "dataProvider" and
"data".

 

Next, use a setter function instead of a public property, so you can
debug the values being passed in. Type the setter function as
specifically as you can, avoid Object.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of nkopcsek
Sent: Tuesday, January 08, 2008 9:51 AM
To: [email protected]
Subject: [flexcoders] Nested Repeaters: Weird Behaviour

 

Hi,

I got some really strange behaviour with nested repeaters.
In this case a repeater is part of a component which is repeated itself
(let's call this component RepeatedComponent, see below for code).
Whenever I add a new item to the dataProvider of the outer repeater it
doesn't add only the new RepeatedComponent but also updates the children
of the other components in an unintended way.

Instead of

1
  11  12  13
2
  21  22  23
3
  31  32  33
x
  x    y    z

I get

1
  11  11  11
2
  22  22  22
3
  33  33  33
x
  x    y    z
.

The strange thing is that all the children of Repeater of the
RepeatedComponent get the same repeaterIndex as the RepeatedComponent
itself.

Thanks in advance for any hints. Any other solution or even a workaround
would help me.


Code:

[RepeatedComponent.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml";>
    <mx:Object id="dataProvider"/>
    <mx:Label text="{dataProvider.label}"/>
    <mx:Repeater id="r" dataProvider="{dataProvider.data}" width="100%"
recycleChildren="true">
        <mx:Label text="label: {r.currentItem.label}"/>
    </mx:Repeater>
</mx:VBox>

[Test.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" xmlns:local="*">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            
            [Bindable]
            private var dataProvider:ArrayCollection = new
ArrayCollection([
                {label:"1", data:new
ArrayCollection([{label:"11"},{label:"12"},{label:"13"}])},
                {label:"2", data:new
ArrayCollection([{label:"21"},{label:"22"},{label:"23"}])},
                {label:"3", data:new
ArrayCollection([{label:"31"},{label:"32"},{label:"33"}])}
                ]);
                
            private function addItem():void {
                dataProvider.addItem({label:"x", data:new
ArrayCollection([{label:"x"},{label:"y"},{label:"z"}])});
            }
        ]]>
    </mx:Script>
    <mx:VBox>
        <mx:Repeater id="r" dataProvider="{dataProvider}" width="100%"
recycleChildren="true">
            <local:RepeatedComponent dataProvider="{r.currentItem}"/> 
        </mx:Repeater>
        <mx:Button label="ClickMe" click="addItem()"/>
    </mx:VBox>
</mx:Application>



 

Reply via email to