Saj*_*aju 0 apache-flex sorting string actionscript-3 arraycollection
我试图对存储在arraycollection中的字符串列表进行排序.但排序结果不正确.请看我的代码.
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();
}
Run Code Online (Sandbox Code Playgroud)
输入:开始,包含,结束,等于IgnoreCase,不等于,匹配,等于
输出:等于IgnoreCase,包含,结束,开始,不等于,匹配,等于
有时候只有一行与另一行交换(如上所述),有些时候根本没有排序.
如果您的数组集合具有字符串列表.您不需要指定SortField的名称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();
Run Code Online (Sandbox Code Playgroud)
O/P:
"value" mx.collections.ArrayCollection (@31ced61)
[0] "Contains"
[1] "End With"
[2] "Equals"
[3] "Equals IgnoreCase"
[4] "Not Equals"
[5] "Start With"
Run Code Online (Sandbox Code Playgroud)
如果arraycollection具有带数据属性的对象,则代码绝对正确.喜欢
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'});
Run Code Online (Sandbox Code Playgroud)
这种情况你需要指定喜欢
var sortField:SortField = new SortField("data");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3776 次 |
| 最近记录: |