在我的flex应用程序中,我的自定义类AudLogDataGrid有一个渲染器函数,它在将数据传递给渲染器之前获取数据列表并对其进行过滤:
private function rendererFunction(item:Object, grid:Object):ClassFactory {
var itemRenderer:ClassFactory = new ClassFactory(AudActionDropDownIR);
var FilteredAudActionData:ArrayCollection = new ArrayCollection(AudActionData.toArray());
ASTDForRow = item.AUD_STEP_TYPE_ID;
FilteredAudActionData.filterFunction = filterTheData;
FilteredAudActionData.refresh();
(itemRenderer as AudActionDropDownIR).TheData = FilteredAudActionData;
return itemRenderer;
}
使用父类中的自定义HTTPService从远程xml文件中检索已排序的AudActionData IList,然后将其作为数据绑定传递:
<components:AudLogDataGrid id="AudLogGrid" y="131" left="10" right="10"
AudLogGridSelectionChange="AudLogGrid_AudLogGridSelectionChangeHandler(event)"
TheData="{getAudLogsResult.lastResult}"
AudActionData="{getAudActionsResult.lastResult}"/>
但是,rendererFunction在从服务器完全检索数据之前运行!有没有办法解决这个问题而不在AS中声明AudLogDataGrid?
谢谢!
答案 0 :(得分:1)
试试这个:
protected var filteredStuff:XMLListcollection = new XMLListCollection;
protected var cf:ClassFactory = new ClassFactory(AudActionDropDownIR);
protected function creationComplete():void {//call from creationComplete "property" in MXML
cf.properties= {TheData:filteredStuff};
filteredStuff.filterFunction = filterTheData;//suggest you use e4x instead, but I can't give exact syntax without seeing your filterFunction
}
//when the data is returned:
protected function gotTheData(e:ResultEvent):void {
filteredStuff.source = e.result.children as XMLList;
}
在AudLogGrid MXML中,只需将cf设置为itemRenderer即可。 XMLListCollection应该处理对引用它的任何东西的改变(现在所有渲染器都应该这样做。这比每次需要渲染器时实例化一个新的ClassFactory要少得多。
顺便说一句,您可以覆盖生命周期方法而无需在AS中编写整个组件。只是说'。