vendredi 11 décembre 2009

Flex trick for callLater and complexe ArrayCollection filtering

I was looking today a way to use a setter in a callLater function in Flex.
Thanks to Kyle Quevillon @ Flex Monkey Patches I found the way to do this in this article.

Actually I was already using the inline function trick to do complexe filtering on ArrayCollection.
If you already tried to filter an ArrayCollection from a variable, you already know that it's not possible using filterFunction since the signature of the filtering function does not accept extra parameters.

Still, you can do it with an inline function the exact same way Kyle Quevillon used it to set a variable via callLater.
Here is an exemple.
private var fooArray:ArrayCollection; // filled with some values.
private function foo(some_value:String):void{
fooArray.filterFunction
= function fooFilter(value:Object):Boolean{
return obj.some_property == some_value;
};
fooArray.refresh();
}

You can even do more complexe filtering that way:

private var fooArray:ArrayCollection; // filled with some values.
private function foo(some_value:String,some_field_to_filter_on:String):void{
fooArray.filterFunction
= function fooFilter(value:Object):Boolean{
return obj[some_field_to_filter_on] == some_value;
};
fooArray.refresh();
}

Aucun commentaire:

Enregistrer un commentaire