我要为上升一个ArrayCollection通过字段名进行排序。这是我的code,我想知道它是否是正确的。你有什么建议吗?
公共静态函数arrayCollectionSort(AR:ArrayCollection中,字段名:字符串,ISNUMERIC:布尔):无效
{VAR dataSortField:=的SortField新的SortField();
dataSortField.name =字段名;
dataSortField.numeric = ISNUMERIC;
VAR numericDataSort:分类=新的排序();
numericDataSort.fields = [dataSortField]
arrCol.sort = numericDataSort;
arrCol.refresh();}
解决方案
在code你是正确的,除了一个类型。 arrCol
应 AR
。在code看起来几乎完全一样的code在博客Flex 的例子,这也是正确的。
只是改变是改变 arrCol
到 AR
象下面这样:
公共静态函数arrayCollectionSort(AR:ArrayCollection中,字段名:字符串,ISNUMERIC:布尔):无效
{
VAR dataSortField:=的SortField新的SortField();
dataSortField.name =字段名;
dataSortField.numeric = ISNUMERIC;
VAR numericDataSort:分类=新的排序();
numericDataSort.fields = [dataSortField]
ar.sort = numericDataSort;
ar.refresh();
}
不知道有数字,但否则一切是正确的。
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();}
解决方案
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.
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.