我得到了这个问题抓过,我发现你的问题,我仍然没有得到它解决了像克里斯托夫建议。
经过一段时间的苦难,我发现了一种避免你提到的问题的方法。
只需使用辅助ArrayCollection进行排序。无论如何,你的排序实例似乎是临时的(你想通过它),所以为什么不使用临时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阵列范围除外),但在至少它解决了我的问题。
哼哼......实际上,当我设置`sort = null`并尝试编辑`ArrayCollection`时,我得到一个异常。除非我调用`ArrayCollection.refresh()`,但是当我这样做时,即使'sort`为'null',数据也会被排序。我卡住了:p – nununo 2011-05-28 16:18:12