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

首頁 > 網站 > WEB開發 > 正文

13.6.遍歷集合對象并記錄位置

2024-04-27 13:52:16
字體:
來源:轉載
供稿:網友
13.6.1. 問題
我想雙向遍歷集合,并保持當前所在位置
13.6.2. 解決辦法
使用ListViewCollection 類的createCursor 方法創建可前后移動的游標。
13.6.3. 討論
可使用視圖游標瀏覽集合數據視圖中所有數據項,訪問和修改集合數據。游標是一個位置指示器,它執行特定位置的數據項。你可以使用集合的createCursor 方法返回一個視圖游標。

游標的各種方法和屬性都由IViewCursor 接口定義。

通過IViewCursor 方法,你可以前后移動游標,用特定條件搜索數據項,獲取指定位置的數據項,保存游標所在位置,以及添加,刪除或修改數據值。

當你使用標準的Flex 集合類如ArrayCollection 和XMLListCollection 時,可直接使用IViewCursor 接口,不需要引用對象實例,例如:
+展開
-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();
}
//這個例子中,IViewCursor對象的findFirst方法根據文本框中的數據定位第一個匹配的集合數據:
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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 惠安县| 墨玉县| 镇巴县| 卓资县| 临桂县| 上饶市| 含山县| 孝义市| 新兴县| 荃湾区| 黑山县| 班玛县| 靖宇县| 休宁县| 台湾省| 彰化县| 蒙阴县| 西充县| 红原县| 丰宁| 彭州市| 磐安县| 苍山县| 工布江达县| 都匀市| 双流县| 德清县| 原阳县| 琼结县| 郑州市| 广丰县| 南开区| 武宁县| 于田县| 日照市| 富蕴县| 元朗区| 芮城县| 金沙县| 元氏县| 诸城市|