0

I have a big ArrayCollection variable. I want to filter it several times and each time assign the filtered result to a different ArrayCollection variable.

So if it has let's say people, fruits and cars. (for illustration purposes) I want to first filter it to only show people, assign the result to a people ArrayCollection, then filter it to show fruits and assign it to a fruits ArrayCollection and so on.

How can I do that? Not the filtering, but the assignment after filtering. Or is it faster to instead run a for-loop through the big ArrayCollection and just add each item into the corresponding smaller ArrayCollection?

1 Answer 1

2

You can use mx.collections.ListCollectionView for that. Say you have the following original ArrayCollection:

var myCollection:ArrayCollection;

Now people:

var peopleList:ListCollectionView = new ListCollectionView(myCollection);
peopleList.filterFuntion = peopleFilterFuntion;
peopleList.refresh();

The same for fruits:

var fruitsList:ListCollectionView = new ListCollectionView(myCollection);
fruitsList.filterFuntion = fruitsFilterFuntion;
fruitsList.refresh();

And cars:

var carsList:ListCollectionView = new ListCollectionView(myCollection);
carsList.filterFuntion = carsFilterFuntion;
carsList.refresh();
Sign up to request clarification or add additional context in comments.

2 Comments

Aren't the filtered out variables kept in memory for when the filterFunction is set to null?
As far as I know, ListCollectionView doesn't create new underlying collection but uses the original ArrayCollection. So it doesn't occupy extra memory for elements.

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.