2012-05-09 56 views
1

我正在使用一些自定義組件構建一個Flex應用程序,我認爲這些應用程序是搞砸了。我試圖在火花數據網格中使用,使用answer here作爲模板。當我嘗試使用下面的函數,自定義Spark DataGrid中未定義的方法「sortByColumns」?

myGrid.sortByColumns(0,true); 

我得到的錯誤:

1061: Call to a possibly undefined method sortByColumns through a 
reference with static type com.components:MyReportGrid. 

任何人都知道如何刪除這個錯誤? MyReportGrid是否掩蓋了火花組件的正確位置?當使用其他一些函數(如invalidateCell())時,我也會得到「未定義的方法」錯誤,不確定它是否與此錯誤相關。

我的數據網格的樣子:

... 
<components:MyReportGrid id="myGrid" dataProvider="{_myData}"...> 
    <components:columns> 
     <fx:Array> 
      <supportClasses:MyColumn ... /> 
      <supportClasses:MyColumn ... /> 
      <supportClasses:MyColumn ... /> 
      ... 

其中MyColumn是一個類如下:

import spark.components.gridClasses.GridColumn; 
public class MyColumn extends GridColumn 
{ 
    ... 
    public function MyColumn(headerText:String="header" width:Number=100 ...) 
    { 
     this.headerText=headerText; 
     ... 
    } 
} 

和MyReportGrid是:

<?xml version="1.0" encoding="utf-8"?> 
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"  
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" 
     width="400" height="300"> 
    import com.components.myClasses.MyColumn; 
    import com.itemRenderers.myItemRenderer; 
    import mx.collections.ArrayCollection; 
    import mx.collections.ArrayList; 
    import mx.collections.ListCollectionView; 
    import spark.components.gridClasses.GridColumn; 
    ... 
    <s:DataGrid width="100%" ... /> 
</s:Group> 

回答

5

這將永遠不會工作,因爲您在MyReportGrid組件上調用myGrid.sortByColumns(0,true);,該組件的基本類型爲Group

一個Group沒有叫sortByColumns

所以您可以任何方法:

  • 在MyReportGrid組件創建一個委託方法

    <?xml version="1.0" encoding="utf-8"?> 
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"  
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    width="400" height="300"> 
        import com.components.myClasses.MyColumn; 
        import com.itemRenderers.myItemRenderer; 
        import mx.collections.ArrayCollection; 
        import mx.collections.ArrayList; 
        import mx.collections.ListCollectionView; 
        import spark.components.gridClasses.GridColumn; 
        ... 
    
        <mx:Script> 
        <![CDATA[ 
        public function sortByColumns(columnIndices:Vector.<int>, isInteractive:Boolean = false):Boolean{ 
         return internalGroupGrid.sortByColumns(columnIndices,isInteractive); 
        } 
        ]]> 
        </mx:Script> 
    
        <s:DataGrid width="100%" id="internalGroupGrid"... /> 
    </s:Group> 
    
  • 使DataGrid中的根標籤您的MyReportGrid組件

    <?xml version="1.0" encoding="utf-8"?> 
    <s:DataGrid xmlns:fx="http://ns.adobe.com/mxml/2009"  
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         width="400" height="300"> 
        import com.components.myClasses.MyColumn; 
        import com.itemRenderers.myItemRenderer; 
        import mx.collections.ArrayCollection; 
        import mx.collections.ArrayList; 
        import mx.collections.ListCollectionView; 
        import spark.components.gridClasses.GridColumn; 
        ... 
    </s:DataGrid> 
    
+0

應該在第一個解決方案中返回sortByColumns的類型爲'void'?另外,是'myGrid.sortByColumns(...);'一個錯字?它應該只是'sortByColumns(...);'在第一個解決方案中? – ggkmath

+0

更改了返回類型的示例。在嵌入MyReportGrid的應用程序中的任何位置,您仍應該調用myGrid.sortByColumns();在本例中,我們只是創建一個佔位符方法,將「MyReportGrid」上的調用「委託」 DataGrid'它包含。 –

+1

感謝丹尼斯,解決方案1現在正在開展工作! – ggkmath

1

嗯,這是有點難以得到沒有看到完整的上下文中的代碼,包括構建腳本和層次結構。但是,據我所知,似乎編譯器缺少有關MyReportGrid是什麼類型的信息。它是否擴展了具有該功能的東西,或者是否實現了「sortByColumns」功能?

如果你正在尋找一種方式,從「類型提示」脫身,你總是可以做 「myGrid [」 sortByColumns「(0,真)」

然而,不推薦;)

順便說一句,在你的exaplanation中,你正在寫一些關於MyDataGrid的東西,這讓我失去了一段時間,直到我意識到這是一個錯字。

我敢肯定,你必須明白,你的類「com.components:MyReportGrid」直接或通過擴展實現該功能。

+0

我更正了MyDataGrid錯字,謝謝Daniel – ggkmath