我得到了這個問題抓過,我發現你的問題,我仍然沒有得到它解決了像克里斯托夫建議。
經過一段時間的苦難,我發現了一種避免你提到的問題的方法。
只需使用輔助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