【问题标题】:Flex: How can I retrieve the data before loading the components?Flex:如何在加载组件之前检索数据?
【发布时间】:2011-12-16 14:42:35
【问题描述】:

在我的 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;
        }

已排序的 AudActionData IList 使用父类中的自定义 HTTPService 从远程 xml 文件中检索,然后作为数据绑定传递:

<components:AudLogDataGrid id="AudLogGrid" y="131" left="10" right="10"
                           AudLogGridSelectionChange="AudLogGrid_AudLogGridSelectionChangeHandler(event)"
                           TheData="{getAudLogsResult.lastResult}"
                           AudActionData="{getAudActionsResult.lastResult}"/>

但是,rendererFunction 在从服务器完全检索数据之前运行!有没有办法在 AS 中不声明 AudLogDataGrid 的情况下解决这个问题?

谢谢!

【问题讨论】:

    标签: apache-flex data-binding actionscript components mxml


    【解决方案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 中编写整个组件。只是说说而已。

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-06
      • 2017-12-09
      相关资源
      最近更新 更多