0
我正在火花DataGrid中進行過濾。但我無法過濾數據。我正在使用dataprovider作爲XML文件。我的代碼是在這裏Flex 4 - 過濾器不工作
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private function xmlListCollectionFilterFun(item : Object) : Boolean
{
var token : String = employeeName.text.toLowerCase();
var eName : String = employeeXMLList.child("Name");
var col : XMLList=tempXML.Employee.Name;
if(eName.toLowerCase().indexOf(token)!= -1)
{
return true;
}
return false;
}
protected function employeeName_changeHandler():void
{
if(employeeName.text.length == 0)
{
employeeXMLList.filterFunction = null;
}
else
{
employeeXMLList.filterFunction = xmlListCollectionFilterFun;
}
employeeXMLList.refresh();
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="tempXML"
source="skins/TextXmlFile.xml" />
<s:XMLListCollection id="employeeXMLList"
source="{tempXML.Employee}" filterFunction="xmlListCollectionFilterFun" />
</fx:Declarations>
<mx:VBox width="80%">
<s:TextInput id="employeeName" change="employeeName_changeHandler()"/>
<s:DataGrid id="dataGrid" dataProvider="{employeeXMLList}" width="100%" >
<s:columns>
<s:ArrayCollection>
<s:GridColumn id="nameCol" dataField="Name" headerText="Name:" />
<s:GridColumn id="idCol" dataField="Id" headerText="ID:"/>
<s:GridColumn id="mobileCol" dataField="Mobile" headerText="Mobile:"/>
<s:GridColumn id="alterCol" dataField="AlterMobile" headerText="Alternative Number"/>
</s:ArrayCollection>
</s:columns>
</s:DataGrid>
</mx:VBox>
</s:Application>
我的XML文件是:
<?xml version="1.0" encoding="UTF-8"?>
<CompanyEmployees version="1">
<Employee>
<Name>John</Name>
<Id>Em234</Id>
<Mobile>09999999999</Mobile>
<AlterMobile>yes</AlterMobile>>
</Employee>
<Employee>
<Name>Ram</Name>
<Id>Em432</Id>
<Mobile>8967452354</Mobile>
<AlterMobile>yes</AlterMobile>
</Employee>
<Employee>
<Name>Raj</Name>
<Id>Em098</Id>
<Mobile>02343235478</Mobile>
<AlterMobile>no</AlterMobile>
</Employee>
它顯示的任何錯誤。但是我無法找到我的錯誤在哪裏以及哪些方面?如果有人找到它,請親密我。
謝謝
我不明白... 1.您想要過濾什麼。 2.爲什麼你從不在過濾器功能中使用「item」參數。 3.預期的結果是什麼。只是有些代碼掉進去沒有幫助; O –