国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開(kāi)發(fā) > 正文

13.6.遍歷集合對(duì)象并記錄位置

2024-04-27 13:52:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
13.6.1. 問(wèn)題
我想雙向遍歷集合,并保持當(dāng)前所在位置
13.6.2. 解決辦法
使用ListViewCollection 類的createCursor 方法創(chuàng)建可前后移動(dòng)的游標(biāo)。
13.6.3. 討論
可使用視圖游標(biāo)瀏覽集合數(shù)據(jù)視圖中所有數(shù)據(jù)項(xiàng),訪問(wèn)和修改集合數(shù)據(jù)。游標(biāo)是一個(gè)位置指示器,它執(zhí)行特定位置的數(shù)據(jù)項(xiàng)。你可以使用集合的createCursor 方法返回一個(gè)視圖游標(biāo)。

游標(biāo)的各種方法和屬性都由IViewCursor 接口定義。

通過(guò)IViewCursor 方法,你可以前后移動(dòng)游標(biāo),用特定條件搜索數(shù)據(jù)項(xiàng),獲取指定位置的數(shù)據(jù)項(xiàng),保存游標(biāo)所在位置,以及添加,刪除或修改數(shù)據(jù)值。

當(dāng)你使用標(biāo)準(zhǔn)的Flex 集合類如ArrayCollection 和XMLListCollection 時(shí),可直接使用IViewCursor 接口,不需要引用對(duì)象實(shí)例,例如:
+展開(kāi)
-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400height="300creationComplete="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>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蓝田县| 罗山县| 乡城县| 施甸县| 延吉市| 武清区| 丘北县| 萨嘎县| 乡城县| 瓮安县| 牡丹江市| 得荣县| 柳河县| 邵东县| 呼伦贝尔市| 宁德市| 广元市| 巍山| 木兰县| 长岛县| 三穗县| 蒲城县| 那曲县| 读书| 偏关县| 肥乡县| 建德市| 亚东县| 花垣县| 安化县| 黎川县| 武宁县| 贵溪市| 米脂县| 上林县| 靖宇县| 成武县| 绥江县| 温宿县| 如皋市| 菏泽市|