+展開(kāi)-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.IViewCursor;
import mx.collections.CursorBookmark;
import mx.collections.ArrayCollection;
[Bindable]
private var coll:ArrayCollection;
[Bindable]
private var cursor:IViewCursor;
private function init():void {
coll = new ArrayCollection([
{city:"Columbus", state:"Ohio", region:"East"},
{city:"Cleveland", state:"Ohio", region:"East"},
{city:"Sacramento", state:"California", region:"West"},
{city:"Atlanta",state:"Georgia", egion:"South"}]);
cursor = coll.createCursor();
}
//這個(gè)例子中,IViewCursor對(duì)象的findFirst方法根據(jù)文本框中的數(shù)據(jù)定位第一個(gè)匹配的集合數(shù)據(jù):
Code View:
private function findRegion():void {
var sort:Sort = new Sort();
sort.fields = [new SortField("region")];
coll.sort = sort;
coll.refresh();
cursor.findFirst({region:regionInput.text});
}
private function findState():void {
var sort:Sort = new Sort();
sort.fields = [new SortField("state")];
coll.sort = sort;
coll.refresh();
cursor.findFirst({region:stateInput.text});
}
]]>
</mx:Script>
<mx:Label text="{cursor.current.city}"/>
<mx:Button click="cursor.moveNext()" label="Next"/>
<mx:Button click="cursor.movePrevious()" label="Previous"/>
<mx:HBox>
<mx:TextInput id="regionInput"/>
<mx:Button click="findRegion()" label="find region"/>
</mx:HBox>
<mx:HBox>
<mx:TextInput id="stateInput"/>
<mx:Button click="findRegion()" label="find state"/>
</mx:HBox>
</mx:VBox>