我试图在运行时访问datagrid,并希望像
一样将数据分配给它public function getGridData(reportsArray:ArrayCollection):void {
reportData = reportsArray;
trace(" The length of the datagrid is "+reportData.length);
graphDataGrid.dataProvider = reportData;
invalidateDisplayList();
}
但是我收到了这个错误
TypeError:错误#1009:无法访问空对象引用的属性或方法。 at views.charts :: ComparisonAnalysis / createDataGrid()[C:\ FlexProjects \ AdvancedMetering \ views \ charts \ ComparisonAnalysis.mxml:32] at views.charts :: ComparisonAnalysis / getGridData()[C:\ FlexProjects \ AdvancedMetering \ views \ charts \ ComparisonAnalysis.mxml:26] at components.CustomReport :: CustomReportSelector / getResultHandler()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ CustomReportSelector.mxml:147] at components.CustomReport :: CustomReportSelector / __ reportingBase_dataGridResultChanged()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ CustomReportSelector.mxml:203] 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() 在mx.core :: UIComponent / dispatchEvent()[C:\ autobuild \ 3.2.0 \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:9298] at components.CustomReport :: ReportingBase / getDataFromServer()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ ReportingBase.as:98] at components.CustomReport :: ReportingBase / getResults()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ ReportingBase.as:78] at components.CustomReport :: CustomReportSelector / getGraphData()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ CustomReportScripts.as:20] at components.CustomReport :: CustomReportSelector / __ getGraphandGridData_click()[C:\ FlexProjects \ AdvancedMetering \ components \ CustomReport \ CustomReportSelector.mxml:248]
有些人可以告诉我,在这个时间点没有实例化数据网格的问题是什么
Sudee [
答案 0 :(得分:0)
如果DataGrid此时未实例化,由于延迟实例化或一般组件生命周期,我将在类上创建一个ArrayCoolection属性,如:
[Bindable] private var graphDataGridDataProvider:ArrayCollection;
并将graphDataGrid的dataProvider绑定到此变量:
<mx:DataGrid id="graphDataGrid" dataProvider="{graphDataGridProvider}" />
然后在你的getGridData方法中设置绑定属性。