1 Reply Latest reply on Jul 24, 2008 1:30 PM by ntsiii

    Editing ArrayCollection with Datagrid Issue

      Hey everyone,

      Here is the problem:

      I have a master ArrayCollection and a secondary ArrayCollection that is a copy of the master. I user the secondary AC as my dataProvider for the Datagrid. I allow the DG to be editable. Once a user changes the data within the DG, it updates the secondary AC and then updates the master AC. The thing is I don't want to update the master AC. I thought if you copy a collection there is no more reference to the master copy. How do I do this? I have tried different ways, secondary = master, secondary = new ArrayCollection(master.source), I even try looping through the master AC and adding each object to the secondary and it still updated the master. I have ran out of options. Can anyone solve this issue?
        • 1. Re: Editing ArrayCollection with Datagrid Issue
          ntsiii Level 3
          An assignment of anything but a primitive value, like String or int uses a reference, and does not make a copy.

          Since the values in the array are objects, you cannot use slice() on the underlying array to get an independant copy.

          You will need to loop over the array, and for each item, create a new item object, assign its properties based on the master item.

          Access the AC's underlying array through the "source" property.