0

I'm pretty new to Flex but I'm taking a few tutorials to try and get the hang of a project I'm working on.

I'm using AS3.

I currently need to just add an arraycollection (A) to an arraycollection (B) that is populating a datagrid. So when the user clicks an option on the left column, the resulting arraycollection (A) will be added to the currently displayed results in the right column.

I also needed it to filter out any duplicate entries. So if B already had a record that was in A, it wouldn't be added.

I think I can just loop through A adding each row to B by using the additem() function, but I'm not exactly sure what syntax to use the loop properly, but if there's a better suggestion, I'm certainly open to it.

Thank so much for any assistance!

1 Answer 1

6

Assuming you already have populated the 2 collections, the merge code would look like this:

var collectionA:ArrayCollection;
var collectionB:ArrayCollection;

for each (var item:Object in collectionB) {
  if (!collectionA.contains(item)) {
    collectionA.addItem(item);
  }
}

where collectionA would be the collection where the unique items from collectionB would be merged into.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.