Flex arraycollection排序不起作用 [英] Flex arraycollection sorting not working
问题描述
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();
输入:开始于,
包含,
结束With,
Equals IgnoreCase,
不等于,
匹配,
等于
输出:Equals IgnoreCase,
包含,
结尾,
开始,
不等于,
匹配,
等于
有些时候只有一行是与另一个交换(如上),有些时候根本没有排序。
解决方案
具有字符串列表的数组集合。你不需要指定SortField的名字 data
。
var value :ArrayCollection = new ArrayCollection(['Start With','Contains','End With','Equals IgnoreCase','Not Equals','Equals']);
var dataSortField:SortField = new SortField(); //留空。
dataSortField.numeric = false;
var dataSort:Sort = new Sort();
dataSort.fields = [dataSortField];
value.sort = dataSort;
value.refresh(); b
$ b $ p $ > valuemx.collections.ArrayCollection(@ 31ced61)
[0]包含
[1]结尾带有
[2]等于
[3]Equals IgnoreCase
[4]Not Equals
[5]开始于
如果arraycollection具有data属性的对象,那么您的代码是绝对正确的。
就像
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'});
这种情况下,您需要指定像
var sortField:SortField = new SortField(data);
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();
}
Input: Start With, Contains, End With, Equals IgnoreCase, Not Equals, Matching, Equals
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.
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"
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'});
This case you need to specify like
var sortField:SortField = new SortField("data");
这篇关于Flex arraycollection排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!