当前位置: 代码迷 >> Web前端 >> 数据罗选(转)
  详细解决方案

数据罗选(转)

热度:241   发布时间:2012-11-23 00:03:29.0
数据筛选(转)

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" width="640" height="400">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.DataGrid;
???
??? private var aryCol:ArrayCollection;
???
?????? var ac:Array=new Array({0:"Visa", 1:21 , 2:"0"},
????????????????????????????? {0:"MasterCard", 1:24 , 2:"1"},
????????????????????????????? {0:"American Express", 1:31 , 2:"2"});
????

?????????????????
private var ad:ArrayCollection=new ArrayCollection(ac);

private function init():void
{
???? dg.dataProvider=ad;????
???????????? ad.filterFunction = filterFunc;
}

private function filterFunc(item:Object):Boolean?? //item 指的就是数据源aryCollection
{
??????????????? var _cb:Boolean = (item["1"] == ageChoose.selectedItem.data) ? true : false;
??????????????? trace("item.1:?? "+item["1"]);
return _cb;
}

private function filterCity(evt:Event):void
{
ad.refresh();
}

]]>
</mx:Script>
<mx:DataGrid id="dg" width="100%" height="100%" rowCount="5"? >
??????????? <mx:columns>
??????????????? <mx:DataGridColumn dataField="0" headerText="name"/>
??????????????? <mx:DataGridColumn dataField="1" headerText="age"/>
??????????????? <mx:DataGridColumn dataField="2" headerText="sex"/>
??????????? </mx:columns>
??????? </mx:DataGrid>

??? <mx:ArrayCollection id="ageSelectAC">
<mx:Object label="21" data="21"/>
<mx:Object label="31" data="31"/>
<mx:Object label="24" data="24"/>
<mx:Object label="27" data="27"/>
</mx:ArrayCollection>
<mx:ComboBox id="ageChoose" width="100" dataProvider="{ageSelectAC}" change="filterCity(event)" x="134" y="339"/>


</mx:WindowedApplication>

  相关解决方案