[Flex] comboBox를 이용한 필터링
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="simpletestCat.send();simpletestFood.send()" layout="horizontal">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.collections.ArrayCollection;
[Bindable]
private var categoryList:ArrayCollection;
[Bindable]
private var foodList:ArrayCollection;
private function filterByCategory(event:Event):void{
if((event.target as ComboBox).selectedIndex == 0){
foodList.filterFunction = null;
}else{
foodList.filterFunction = catFilter;
}
foodList.refresh();
foodListBox.selectedIndex =0
}
private function catFilter(item:Object):Boolean{
return item.category_name == categorySelect.selectedItem.category_name;
}
]]>
</mx:Script>
<mx:HTTPService id="simpletestCat"
url="assets\categorylist.xml"
result="categoryList=simpletestCat.lastResult.list.category;categoryList.addItemAt('All', 0);categorySelect.selectedIndex=0"/>
<mx:HTTPService id="simpletestFood"
url="assets\foodlist.xml"
result="foodList=simpletestFood.lastResult.list.food"/>
<mx:ComboBox id="categorySelect" change="filterByCategory(event)"
dataProvider="{categoryList}"
labelField="category_name"/>
<mx:ComboBox id="foodListBox"
dataProvider="{foodList}"
labelField="product_name"
width="200"/>
</mx:Application>