首页 > 代码库 > flex中对ArrayCollection进行排序

flex中对ArrayCollection进行排序

Flex中对ArrayCollection进行排序  

<?xml version="1.0" encoding="utf-8"?>  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">       <mx:Script>           <![CDATA[              import mx.collections.SortField;              import mx.collections.Sort;              import mx.collections.ArrayCollection;              private var acSort:ArrayCollection=              new ArrayCollection([{id:0,userName:"zhangSan",age:21},                                   {id:2,userName:"liSi",age:24},                                   {id:1,userName:"wangWu",age:31}]);                                          private function sortAc():ArrayCollection{                   var sort:Sort=new Sort();                  //按照ID升序排序                   sort.fields=[new SortField("id")];                                    //按照userName降序排序                   sort.fields=[new SortField("userName",true,true)];                                    //先按ID升序,再按userName降序                   sort.fields[new SortField("id"),new SortField("userName",true,true)];                   acSort.sort=sort;                   acSort.refresh();//更新                  return acSort;               }                                     ]]>       </mx:Script>  </mx:Application>

 

flex中对ArrayCollection进行排序