Problem in fetching array collection updated data

0 views
Skip to first unread message

flex

unread,
Sep 13, 2011, 5:07:42 AM9/13/11
to HyderabadFX
hi friends
i am run time creating instance of 1 component and assigning arraycol
data to that component arracol.
When i'm changing value in 1st instance it also giving me change in
all \.

See the example below and click on 'Check Change' button where i'm
alert changed value for 1st 2 instances where it gives me same even i
changed 1st instance checkbox.


main.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"

creationComplete="windowedapplication1_creationCompleteHandler(event)">
<s:layout>
<s:VerticalLayout/>
</s:layout>

<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;

protected function
windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
for(var i:Number=0; i < 4; i++){
var child:comp_DG = new comp_DG();
myTab.addChild(child);
child.arrColInfo = arrCol;
child.myLBL.text = ''+i;
child.label=''+i;
}
}

protected function button1_clickHandler(event:MouseEvent):void
{
var child:comp_DG = myTab.getItemAt(0) as comp_DG;
var child2:comp_DG = myTab.getItemAt(1) as comp_DG;

Alert.show(''+child.arrColInfo.getItemAt(0).selected+' :
'+child2.arrColInfo.getItemAt(0).selected);
//Alert.show(''+child.myLBL.text+' : '+child2.myLBL.text);
}

]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here
-->
<s:ArrayCollection id="arrCol">
<fx:Object label='1' selected="false" />
<fx:Object label='2' selected="false" />
<fx:Object label='3' selected="false" />
<fx:Object label='4' selected="false" />
<fx:Object label='5' selected="false" />
<fx:Object label='6' selected="false" />
<fx:Object label='7' selected="false" />
<fx:Object label='8' selected="false" />
<fx:Object label='8' selected="false" />
<fx:Object label='10' selected="false" />
</s:ArrayCollection>
</fx:Declarations>

<mx:TabNavigator id="myTab" width="100%" height="100%" >
</mx:TabNavigator>
<s:Button label="Check Change" click="button1_clickHandler(event)" />
</s:WindowedApplication>




comp_DG.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
creationComplete="group1_creationCompleteHandler(event)">

<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
public var arrColInfo:ArrayCollection = new ArrayCollection();

protected function
group1_creationCompleteHandler(event:FlexEvent):void
{
dg.dataProvider = arrColInfo;
}

]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here
-->
</fx:Declarations>
<s:VGroup >
<s:TextInput id="myLBL" />

<mx:DataGrid id="dg" width="100%" height="300"
>
<mx:columns>
<mx:DataGridColumn headerText="Select"
width="50">
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalAlign="center"
verticalAlign="middle">
<s:CheckBox id="chb" selected="{data.selected}"
change="data.selected=chb.selected;"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>

<mx:DataGridColumn headerText="Label" dataField="label"
width="300" />
</mx:columns>
</mx:DataGrid>

</s:VGroup>
</mx:HBox>

is any way there to get changes made by user in datagrid?
thanks you.

venu reddy

unread,
Sep 13, 2011, 6:42:32 AM9/13/11
to hyder...@googlegroups.com
Hi,
You are trying to do the Assignment operation which will be having the bidirectional references. So better way to copy the arraycollection use "Destination ArrayCollection = ObjectUtil.Copy(sourceArrayCollection)" .Hope this will solve your problem.


Thanks,
Venu.


--
You received this message because you are subscribed to the Google Groups "HyderabadFX" group.
To post to this group, send email to hyder...@googlegroups.com.
To unsubscribe from this group, send email to hyderabadfx...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hyderabadfx?hl=en.




--
Venu Reddy
Reply all
Reply to author
Forward
0 new messages