![](/img/trans.png)
[英]Can I convert a JSON string to a Flex ArrayCollection in without changing the item order?
[英]Flex arraycollection sorting not working
我正在嘗試對存儲在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();
}
輸入:開頭為,包含,結尾為,等於IgnoreCase,不等於,匹配,等於
輸出:等於IgnoreCase,包含,結尾為,開頭為,不等於,匹配,等於
有時只有一行與另一行交換(如上所述),有時根本沒有排序。
如果您的數組集合具有字符串列表。 您無需為案例data
指定SortField的名稱。
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的對象具有數據屬性,則您的代碼絕對正確。 喜歡
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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.