views:

25

answers:

2

Hi,

I have an issue in flex which is causing a bit of a headache!

I am adding objects to an ArrayCollection but in doing so, another ArrayCollection is also picking up these changes even though there is no binding occurring.

I can see from the debug that the two ACs have the same address but for the life of me can't figure out why.

I have two Array Collections:

model.index.rows //The main array collection

model.index.holdRows //The array collection that imitates the above

This phantom data binding occurs only for the first iteration in the loop and for all others it will just write it the once.

The reason this is proving troublesome is that it creates duplicate entries in my datagrid.

public override function handleMessage(message:IMessage):void
    {

        super.handleMessage(message);
        if (message is IndexResponse)
        {
           var response:IndexResponse = message as IndexResponse;

            model.index.rows.removeAll();
            model.index.indexIsEmpty = response.nullIndex;

            if (model.index.indexIsEmpty !== true)
            {

                //Update the index model from the response. Note: each property of the row object will be shown in the UI as a column in the grid
                response.index.forEach(function(entry:EntryData, i:int, a:Array):void
                    {
                        var row:Object = { fileID: entry.fileID, dadName: entry.dadName };

                        entry.tags.forEach(function(tag:Tag, i:int, a:Array):void
                            {
                                row[tag.name] = tag.value;
                            });

                        model.index.rows.addItem(row);

                    });

              if(model.index.indexForNetworkView == true){

                model.index.holdRows.source = model.index.holdRows.source.concat(model.index.rows.source);
                model.index.indexCounter++;
                model.index.indexForNetworkView = false;
                controller.indexController.showNetwork(model.index.indexCounter);                   
              }
                model.index.rows.refresh();
                controller.networkController.show();                  
            }

        }

Has anyone else who has encountered something simillar propose a solution?

A: 

Hey,

I asked the same question in this stackoverflow thread and it is explained what is going on, and what can you do to solve it:

Changes to one variable propagates to another

Ladislav

Ladislav
Great help thank you very much!
James
No problem, had the same issue couple of months back and as you can see was also solved right here:)
Ladislav
A: 

After consulting the afore mentioned thread I solved the problem thus:

I had the code set out in another class like so:

model.index.rows = model.index.holdRows;

This seem to propagate throughout the code. Instead, I changed this line to:

model.index.rows = new ArrayCollection(model.index.holdRows.source.concat());

as suggested in the thread mentioned. This removed the duplicate entry for me! :o)

James