If you have an ArrayCollection with a filter function set and you loop through the items, you’ll only see the items which match the filter. The catch is sometimes you want to see them all. Initially I was doing the following.
var filterFunction:Function = arrayCollection.filterFunction; arrayCollection.filterFunction = null; arrayCollection.refresh(); for each (var obj:Object in arrayCollection) { // do stuff } arrayCollection.filterFunction = filterFunction; arrayCollection.refresh();
This worked but was pretty ugly. Here’s a nicer approach:
for each (var obj:Object in arrayCollection.source) { // do stuff }
What I keep finding in Flex is that I’m able to come up with complex code to solve simple problems but when I revisit it months later there’s usually a more straight-forward solution.
Hope this helps,
Hillel
Hillel,
Do you have the complete source code for this.I am looking for a similar example which is needed in my project.
My code :
(value as ArrayCollection).filterFunction = filterFunction;
private function filterFunction(item:Object):Boolean {
if (_matchKey == false )
return true;
}
return text.length == 0 || isMatch(itemToLabel(item));
}
Krishna,
I’m sorry, I’m not sure what source you’re looking for.
Hillel,
Do you have the complete as file,which gives all the items in the arraycollection ignoring the filter. I tried using the code above as said by you, it wasn’t working.
Krishna,
I’m sorry, there’s no as file. The post is just pointing out that ArrayCollections have a property called “source” which gives you access to the raw array (without any of the ArrayCollection’s filters).