在对我的数据提供程序(数组集合)应用了数字排序之后,我不能通过tilelist对项进行重新排序。我是否需要从arrayCollection中删除排序。如果是这样,是否只是设置collection.sort = null的情况?
var sortField:SortField=new SortField();
sortField.name="order";
sortField.numeric=true;
var sort:Sort=new Sort();
sort.fields=[sortField];发布于 2009-08-04 13:42:18
将排序设置为null实际上应该删除集合的排序。您可能需要执行一个可选的refresh()。
发布于 2009-10-14 10:30:29
Source
Adobe Flex -按日期对ArrayCollection进行排序
/** * @params data:Array * @return data dataCollection:Array **/私有函数orderByPeriod(data: Array ):Array { var dataCollection:ArrayCollection = new ArrayCollection (Data);//将数组转换为ArrayCollection执行排序函数var dataSortField:SortField = new SortField();dataSortField.name = "period";//将排序字段赋给保存日期字符串的字段var numericDataSort:Sort = new Sort();numericDataSort.fields = dataSortField;dataCollection.sort = numericDataSort;dataCollection.refresh();return dataCollection.toArray();}
发布于 2011-07-21 23:26:20
我也遇到了这个问题,我找到了你的问题,但我仍然没有像Christophe建议的那样解决它。
在经历了一段时间的痛苦之后,我发现了一种避免你提到的问题的方法。
只需使用辅助ArrayCollection来执行排序。无论如何,您的Sort实例似乎是临时的(您希望通过它),所以为什么不使用临时ArrayCollection呢?
下面是我的代码的样子:
// myArrayCollection is the one to sort
// Create the sorter
var alphabeticSort:ISort = new Sort();
var sortfieldFirstName:ISortField = new SortField("firstName",true);
var sortfieldLastName:ISortField = new SortField("lastName",true);
alphabeticSort.fields = [sortfieldFirstName, sortfieldLastName];
// Copy myArrayCollection to aux
var aux:ArrayCollection = new ArrayCollection();
while (myArrayCollection.length > 0) {
aux.addItem(myArrayCollection.removeItemAt(0));
}
// Sort the aux
var previousSort:ISort = aux.sort;
aux.sort = alphabeticSort;
aux.refresh();
aux.sort = previousSort;
// Copy aux to myArrayCollection
var auxLength:int = aux.length;
while (auxLength > 0) {
myArrayCollection.addItemAt(aux.removeItemAt(auxLength - 1), 0);
auxLength--;
}这不是最整洁的代码,它有一些奇怪的破解,比如用auxLength代替aux.length (这个给了我-1数组范围异常),但至少它解决了我的问题。
https://stackoverflow.com/questions/1224853
复制相似问题