Thursday, December 16, 2010

Flex 3 ObjectUtil.copy()

So the other day at work, I was working with a datagrid whose data provider was an arrayCollection that was holding a list of VO's. What I wanting to do was edit the selected VO in another component.

What I was doing was passing the VO into the component like:
exampleComponent.exampleVO = arrayCollectionExample[dataGrid.selectedIndex];
This was doing what I wanted, set the component VO to the selected VO. Worked great.

Now the problem I ran into was when I updated the VO and an error occurred. Although it wasn't updating in the database, the datagrid was updated. The item was binded I believe.

To corrected this I found this ObjectUtil.copy().
exampleComponent.exampleVO = ObjectUtil.copy(arrayCollectionExample[dataGrid.selectedIndex]) as exampleVO;

It worked for me and there was no more binding to the data grid. :)

No comments: