如何在Flex的一个ArrayCollection排序 [英] How to sort an ArrayCollection in Flex

查看:120
本文介绍了如何在Flex的一个ArrayCollection排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为上升一个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在博客<一href="http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/">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.

这篇关于如何在Flex的一个ArrayCollection排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆