我正在使用一些自定義組件構建一個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>
應該在第一個解決方案中返回sortByColumns的類型爲'void'?另外,是'myGrid.sortByColumns(...);'一個錯字?它應該只是'sortByColumns(...);'在第一個解決方案中? – ggkmath
更改了返回類型的示例。在嵌入MyReportGrid的應用程序中的任何位置,您仍應該調用myGrid.sortByColumns();在本例中,我們只是創建一個佔位符方法,將「MyReportGrid」上的調用「委託」 DataGrid'它包含。 –
感謝丹尼斯,解決方案1現在正在開展工作! – ggkmath