因此,在我的RIA中,有一个mx:DataGrid连接到某个Web服务,它从该服务获取数据(DataProvider)。我有一个简单的文本文件。我想更改文本字段中的文本,以便在我的表格中只看到包含输入文本的行,这些行包含任何列中任何单词的某些部分。这样的事情怎么做呢?
yizd12fk1#
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init();"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import spark.events.TextOperationEvent; [Bindable] private var dataProvider:ArrayCollection; private var filterString:String; private function init():void { dataProvider = new ArrayCollection( [ { name: "Alan", surname: "Cooper" }, { name: "James", surname: "Gosling" }, { name: "Mike", surname: "Chambers" }, { name: "Hare", surname: "Krishna" }, { name: "Otto", surname: "Thunder" } ]); dataProvider.filterFunction = filterFunction; } private function filterFunction(item:Object):Boolean { if (!filterString) return true; for (var p:String in item) { var string:String = item[p] as String; if (!string) continue; if (string.toLocaleLowerCase().indexOf(filterString) >= 0) return true; } return false; } private function input_changeHandler(event:TextOperationEvent):void { filterString = input.text.toLocaleLowerCase(); dataProvider.refresh(); } ]]> </fx:Script> <s:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/> </s:layout> <s:TextInput id="input" change="input_changeHandler(event)"/> <mx:DataGrid dataProvider="{dataProvider}"/> </s:Application>
1条答案
按热度按时间yizd12fk1#