我有一个datagrid,其中dataProvider是两种不同类型的对象(FolderVO和FileVO)的ArrayCollection。我有一个size列,在FolderVO的情况下,它由一个名为contentSize的属性填充,在FileVO的情况下,它由size属性填充(差异由itemrenderer处理)。
这意味着我需要为size列实现一个排序函数,如下所示:
protected function sortSize(dataA:Object, dataB:Object):int{
var order:int = 0;
if(dataA is FolderVO && dataB is FolderVO){
order = ObjectUtil.numericCompare(dataA.contentSize, dataB.contentSize);
}else if(dataA is FileVO && dataB is FileVO){
order = ObjectUtil.numericCompare(dataA.size, dataB.size);
}else if(dataA is FolderVO && dataB is FileVO){
order = 1;
}else if(dataA is FileVO && dataB is FolderVO){
order = -1;
}
return order;
}
该函数运行得很好,但在return语句之后,我得到了这个错误:
Error: Find criteria must contain at least one sort field value.
at mx.collections::Sort/findItem()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\Sort.as:491]
at mx.collections::ListCollectionView/getItemIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:513]
at ListCollectionViewCursor/collectionEventHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:2154]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:833]
at mx.collections::ListCollectionView/internalRefresh()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1275]
at mx.collections::ListCollectionView/refresh()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:402]
at mx.controls::DataGrid/sortByColumn()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\DataGrid.as:3560]
at mx.controls::DataGrid/headerReleaseHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\DataGrid.as:4909]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
at mx.controls.dataGridClasses::DataGridHeader/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\dataGridClasses\DataGridHeader.as:1259]
正如你所注意到的,错误发生在flex框架本身,而不是我的代码中。所以我真的被困在这里了。帮助将非常感谢。
1条答案
按热度按时间5m1hhzi41#
显然,导致错误的原因是,在某个时候,Flex框架假设ArrayCollection中包含的所有对象都有一个 size 属性,因此即使我使用自定义排序函数,它也会尝试获取某个对象的值。
解决方案是向我的FolderVO添加一个默认值为0的伪 size 属性。