我想按字段名称将Arraycollection排序为升序.这是我的代码,我想知道它是否正确.你有什么建议吗?
public static function arrayCollectionSort(ar:ArrayCollection,fieldName:String,isNumeric:Boolean):void {var dataSortField:SortField = new SortField(); dataSortField.name = fieldName; dataSortField.numeric = isNumeric; var numericDataSort:Sort = new Sort(); numericDataSort.fields = [dataSortField]; arrCol.sort = numericDataSort; arrCol.refresh();}
解决方法
您拥有的代码是正确的,但类型除外. arrCol应该是ar.代码看起来几乎与博客
Flex Examples中的代码完全一样,这也是正确的.
只需更改是将arrCol更改为如下所示:
public static function arrayCollectionSort(ar:ArrayCollection,isNumeric:Boolean):void { var dataSortField:SortField = new SortField(); dataSortField.name = fieldName; dataSortField.numeric = isNumeric; var numericDataSort:Sort = new Sort(); numericDataSort.fields = [dataSortField]; ar.sort = numericDataSort; ar.refresh(); }
不确定数字,但其他一切都是正确的.