国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 辽阳市| 栾城县| 大同市| 沙河市| 万荣县| 昭觉县| 巴南区| 板桥市| 平山县| 色达县| 德江县| 仪陇县| 五指山市| 紫云| 黎平县| 临泉县| 峨边| 洞口县| 出国| 遵化市| 岑溪市| 大荔县| 兴隆县| 中方县| 普洱| 灵丘县| 东安县| 库车县| 拉孜县| 徐汇区| 乐清市| 清涧县| 西乌珠穆沁旗| 胶南市| 龙泉市| 合水县| 灵武市| 勃利县| 孙吴县| 牙克石市| 华容县|