2007年11月11日 @ 22:38
Simple filterFunction Example
Simple filterFunction Example
Posted by brandonthedeveloper at November 10th, 2007
I’ve been meaning to knock out a bunch of quick Flex examples based on functions I use quite a bit in my day to day Flex coding.
Using the mx.collections.filterFunction is really easy but seems to throw off a lot of devs new to Flex. It sounds way harder than it is. :)
Here’s an example:
The filterFunction is used to filter an Array Collection to only show the items that match certain criteria. In this example, the user makes a selection from the ‘Radio Button Group’ and that fires off the Event Handler ( bandRBGClickHandler ).
private function bandRBGClickHandler(evt:Event):void {
// call the filter function
bandAryCol.filterFunction = bandFilterFunction;
// refresh the array collection
bandAryCol.refresh();
}
Inside the Event Handler, the Array Collection has a filterFunction property that gets set to the filterFunction we want to use ( bandFilterFunction ). Internally, the bandAryCol.filterFunction is iterating through the objects in the collection to find which object’s ‘band’ property match the radio button’s selected value.
private function bandFilterFunction(obj:Object):Boolean {
// return whether or not the current bandAryCol index meets the filter criteria
return (obj.band == bandRBG.selectedValue);
}
After the filterFunction has run, the refresh() method is called to reset the Array Collection’s current items. This does not actually remove any items from the collection, just does not show the items that did not match the filterFunction conditions.
That’s about it. Not hard at all and very handy. :)
Filed under: 资料 · Tags: filter
Articles related:
Writing a FadeToHistory Hydra Filter, part 1 (2007-10-18 13:7:50)
Welcome to the Hydra Filter Gallery! (2007-10-8 10:48:0)
通过组合框(ComboBox)来过滤DataGrid (2007-6-22 22:39:47)
How To Filter An ArrayCollection That Is The Data (2007-5-18 13:42:24)
Using a Data Manager and Filtering Data In A Flex (2007-5-18 13:40:16)
Leave a Comment
◎welcome to give out your point。
