对ArrayCollection中的项目进行排序+光标的用法

xiaoxiao2026-05-25  14

一、

 

1.创建一个新的Sort对象

2.创建一个或多个SortField对象

3.将第2步中创建的SortField对象作为数组赋值到Sort对象的fields属性

4.将ArrayCollection的sort属性赋值为Sort对象

5.调用ArrayCollection的refresh()方法,使排序生效

 

如:

 

 var prodSort:Sort=new Sort(); var sortField:SortField=new SortField("product"); prodSort.fields=new Array(sortField); aItems.sort=prodSort; aItems.refresh();

 

当指定多个时如下:

 

 var prodSort:Sort=new Sort(); var sortField1:SortField=new SortField("product");(此处是优先对product字段排序)

 var sortField2:SortField=new SortField("price"); prodSort.fields=new Array(sortField1,sortField2); aItems.sort=prodSort; aItems.refresh();

 

二、

 

光标并不专门针对ArrayCollection,任何实现了ICursorView接口的类都可以使用光标。

在集合类中使用光标的一般步骤如下:

1.使用creatCursor()方法在ArrayCollection中创建光标。

2.对ArrayCollection进行排序。

3.使用光标中的findFirst()、findAny()、moveNext()方法移动并在ArrayCollection中查找项目。

如下:

   var cursor:IViewCursor = aItems.createCursor();   sortItems();   var found:Boolean = cursor.findFirst(item);

 

当前对象:cursor.current

相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5049361.html

最新回复(0)