假设ArrayCollection(m_myArrayCollection)属性有userID,userName,regTime。
1、按regTime排序
程序代码
var m_myArrayCollection:ArrayCollection = new ArrayCollection();
//先加入N个测试object
m_myArrayCollection.addItem({userID:0,userName:AAA,regTime:2008-02-28},{userID:1,userName:BBB,regTime:2008-02-29},{userID:2,userName:CCC,regTime:2008-03-01});
//设定Sort对象
var m_sort:Sort = new Sort();
//默认按升序排序
m_Sort.fields = [new SortField("regTime")];
//按降序排序,把上一句注释,比对一下效果
//m_Sort.fields = [new SortField("regTime",true,true)];
//把排序方法指定给m_myArrayCollection
m_myArrayCollection.sort = m_sort;
//如果不执行refresh,啥事都不发生
m_myArrayCollection.refresh();
2、先按userID降序排序,再按userName升序排序
程序代码
var m_myArrayCollection:ArrayCollection = new ArrayCollection();
//先加入N个测试object
m_myArrayCollection.addItem({userID:0,userName:AAA,regTime:2008-02-28},{userID:1,userName:BBB,regTime:2008-02-29},{userID:2,userName:CCC,regTime:2008-03-01});
//设定Sort对象
var m_sort:Sort = new Sort();
//默认按升序排序
m_Sort.fields = [new SortField("userID",true,true),new SortField("userName")];
//把排序方法指定给m_myArrayCollection
m_myArrayCollection.sort = m_sort;
//如果不执行refresh,啥事都不发生
m_myArrayCollection.refresh();