如何在 Flex 中对 ArrayCollection 进行排序 [英] How to sort an ArrayCollection in Flex
本文介绍了如何在 Flex 中对 ArrayCollection 进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按 fieldName 按升序对 Arraycollection 进行排序.这是我的代码,我想知道它是否正确.您有什么建议吗?
I want to sort an Arraycollection by fieldName as ascending. Here's my code and I want to know whether it's right. Do you have any suggestions?
public static function arrayCollectionSort(ar:ArrayCollection, fieldName:String, isNumeric:Boolean):void
{var dataSortField:SortField = new SortField();
dataSortField.name = fieldName;
dataSortField.numeric = isNumeric;
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
arrCol.sort = numericDataSort;
arrCol.refresh();}
推荐答案
您拥有的代码是正确的,除了类型.arrCol
应该是 ar
.代码看起来几乎与博客中的代码Flex 示例,这也是正确的.
The code you have is correct, except for a type. arrCol
should be ar
. The code looks almost exactly like the code at the blog Flex Examples, which is also correct.
只是将 arrCol
更改为 ar
如下所示:
Just change is change arrCol
to ar
like below:
public static function arrayCollectionSort(ar:ArrayCollection, fieldName:String, isNumeric:Boolean):void
{
var dataSortField:SortField = new SortField();
dataSortField.name = fieldName;
dataSortField.numeric = isNumeric;
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
ar.sort = numericDataSort;
ar.refresh();
}
不确定数字,但其他一切都是正确的.
Not sure with numeric but otherwise everything else is correct.
这篇关于如何在 Flex 中对 ArrayCollection 进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文