Hi,
I need to merge 2 arrayCollection and avoid duplicates. They contain objects with their own attributes. I would like to avoid duplicates.
thanks
Hi,
I need to merge 2 arrayCollection and avoid duplicates. They contain objects with their own attributes. I would like to avoid duplicates.
thanks
If the 2 ArrayCollections potentially contain exactly the same objects, it would be
if (acDestination.getItemIndex(acSource[i]) == -1)
// add to the destination
If the objects aren't exactly the same but you'd like to avoid duplicate values on a key field, try a filter function on the destination ArrayCollection.
var array1:ArrayCollection = new ArrayCollection();
var array2:ArrayCollection = new ArrayCollection();
var array3:ArrayCollection = new ArrayCollection(array1.source);
for(var i:int;i<array2.length;i++){
if (!(array3.contains(array2.getItemAt(i))))
array3.addItem(array2);
}
That's the simplest algorithm, and works for not so large lists. The contains method will check for object references and you should use your custom method in case you are defining duplicates by looking on objects properties.