这是未经测试的代码,但它应该让你的正确道路上。
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