代码之家  ›  专栏  ›  技术社区  ›  Chepech

查找条件必须至少包含一个排序字段值

  •  1
  • Chepech  · 技术社区  · 15 年前

    我有这个DataGrid,它的DataProvider是两种不同类型的对象(foldervo和filevo)的ArrayCollection。 我有一个大小列,在foldervo的情况下,它由一个名为contentsize的属性填充,而在filevo的情况下,它由大小属性填充(差异由itemrenderer处理)。

    这意味着我需要为大小列实现一个排序函数,这里是:

    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;
        }
    

    函数运行得很好,但是在返回语句之后,我得到了这个错误:

    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 回复  |  直到 15 年前
        1
  •  4
  •   Chepech    15 年前

    好吧,我自己找到了…

    显然,该错误是由于在某一点上,flex框架假定arraycollection中包含的所有对象都具有 大小 属性,因此即使使用自定义排序函数,它也会尝试获取某个对象的值。

    解决方案是添加一个虚拟对象 大小 属性设置为默认值为0的foldervo。

    希望这对外面的人有帮助。

    拉兹!