导航

ArrayCollection进行排序

Posted on 2015-01-15 00:03  同仁员  阅读(165)  评论(0)    收藏  举报

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>