這是未經測試的代碼,但它應該讓你的正確道路上。
private function sortCollection(list:ArrayCollection):ArrayCollection {
var sort:ISort = new Sort();
var sortField:SortField = new SortField();
sortField.name = "DmvValue3";
sortField.caseInsensitive = true;
sortField.numeric = true;
sortField.descending = true;
sort.fields = [sortField];
list.sort = sort;
list.refresh();
return list;
}
[更新]
private function sortCollection(list:ArrayCollection):ArrayCollection {
var sort:ISort = new Sort();
var sortField:SortField = new SortField();
//sortField.name = "DmvValue3";
//sortField.caseInsensitive = true;
////sortField.numeric = true;
//sortField.descending = true;
//sort.fields = [sortField];
sort.compareFunction = myCompare;
list.sort = sort;
list.refresh();
return list;
}
public function myCompare(a:Object, b:Object, fields:Array = null):int {
if(a["DmvValue3"] < b["DmvValue3"])
return -1; // -1, if a should appear before b in the sorted sequence
if(a["DmvValue3"] == b["DmvValue3"])
return 0; // 0, if a equals b
if(a["DmvValue3"] > b["DmvValue3"])
return 1; // 1, if a should appear after b in the sorted sequence
}
我沒有看到你打電話list.refresh()應用排序後。 –
基本上我需要按字母順序排序而不是第一個對象的每個對象的第三部分或屬性。 – yams
刷新與排序對象的某個屬性無關。 – yams