Flex arraycollection 排序不起作用 [英] Flex arraycollection sorting not working

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

问题描述

我正在尝试对数组集合中存储的字符串列表进行排序.但排序结果不正确.请看我的代码.

I am trying to sort a list of string stored in an arraycollection. But the sorted result is not correct. Please see my code.

spark.collections.Sort

if(value is ArrayCollection){
            var sort:Sort=new Sort();
            var sortField:SortField = new SortField("data")
            sortField.numeric=false;
            sort.fields=[sortField];

            ArrayCollection(value).sort=sort;
            ArrayCollection(value).refresh();
        }

输入:开始于,包含,结束于,等于 IgnoreCase,不等于,匹配,等于

Input: Start With, Contains, End With, Equals IgnoreCase, Not Equals, Matching, Equals

输出:等于 IgnoreCase,包含,结束于,从...开始,不等于,匹配,等于

Output: Equals IgnoreCase, Contains, End With, Start With, Not Equals, Matching, Equals

有时只有一行与另一行交换(如上),有时根本没有排序.

Some time only one row is swapping with another(as above), some time no sorting at all.

推荐答案

如果你的数组集合有字符串列表.您无需为您的案例指定 SortField 的名称 data.

In case of your array collection having list of string. you need not specify name of SortField your case data.

            var value:ArrayCollection = new ArrayCollection(['Start With','Contains','End With','Equals IgnoreCase','Not Equals','Equals']);
            var dataSortField:SortField = new SortField(); //Leave it empty.
            dataSortField.numeric = false;

            var dataSort:Sort = new Sort();
            dataSort.fields=[dataSortField];

            value.sort = dataSort;
            value.refresh();

o/p:

   "value"  mx.collections.ArrayCollection (@31ced61)   
[0] "Contains"  
[1] "End With"  
[2] "Equals"    
[3] "Equals IgnoreCase" 
[4] "Not Equals"    
[5] "Start With"

如果 arraycollection 具有带有数据属性的对象,则您的代码绝对正确.喜欢

If arraycollection having object with data property your code is absolutly correct. like

            var value:ArrayCollection = new ArrayCollection();
            value.addItem({data:'Start With'});
            value.addItem({data:'Contains'});
            value.addItem({data:'End With'});
            value.addItem({data:'Equals IgnoreCase'});
            value.addItem({data:'Not Equals'});
            value.addItem({data:'Equals'});

这种情况你需要指定like

This case you need to specify like

var sortField:SortField = new SortField("data");

这篇关于Flex arraycollection 排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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