sort the arraycollection in Flex
<?xml version="1.0"encoding="Utf-8"?> <mx:application xmlns:mx="Http://www.adobe.com/2006/mxml"layout="Absolute"> <mx:Script> <![cdata[ImportMx.collections.SortField; ImportMx.collections.Sort; Importmx.collections.ArrayCollection; Private varacsort:arraycollection=NewArrayCollection ([{id:0,username:"Zhangsan", age:21}, {ID:2,username:"LiSi", age:24}, {ID:1,username:"Wangwu", age:31}]); Private functionSortac (): arraycollection{varsort:sort=NewSort (); //Sort by ID ascendingsort.fields=[NewSortField ("id")]; //sort in descending order of usernamesort.fields=[NewSortField ("UserName",true,true)]; //first by ID ascending, then by username descendingsort.fields[NewSortField ("id"),NewSortField ("UserName",true,true)]; Acsort.sort=sort; Acsort.refresh ();//Update returnAcsort; } ]]> </Mx:script> </Mx:application>
Sort the arraycollection in Flex