将远程对象结果转换为flex中的数组集合

时间:2010-06-11 04:31:45

标签: php flex air

嗨,伙计们,  即时通讯使用zend_amf和flex。我的问题是我必须使用数组集合填充我的高级数据网格。这个数组有一个孩子。

示例:

    [Bindable]
 private var dpHierarchy:ArrayCollection = new ArrayCollection([
  {trucks:"Truck", children: [
         {trucks:"AMC841", total_trip:1, start_time:'3:46:40 AM'},
         {trucks:"AMC841", total_trip:1, start_time:'3:46:40 AM'}])
         ]};

但是我的数据网格的数据源应该来自数据库,如何将结果从远程对象转换为具有与我的示例相同的格式的数组集合,或者任何其他方式。

这是我的高级数据网格

<mx:AdvancedDataGrid id="datagrid"
                         width="500" height="200" lockedColumnCount="1" lockedRowCount="0" horizontalScrollPolicy="on" includeIn="loggedIn" x="67" y="131">
        <mx:dataProvider>
            <mx:HierarchicalData id="dpHierarchytest" source="{dp}"/>
        </mx:dataProvider>
        <mx:groupedColumns>
            <mx:AdvancedDataGridColumn dataField="trucks"
                                       headerText="Trucks"/>
            <mx:AdvancedDataGridColumn dataField="total_trip"
                                       headerText="Total Trip"/>
            <mx:AdvancedDataGridColumnGroup headerText="PRECOOLING">
                <mx:AdvancedDataGridColumnGroup headerText="Before Loading">
                    <mx:AdvancedDataGridColumn dataField="start_time" headerText="Start Time"/>
                    <mx:AdvancedDataGridColumn dataField="end_time" headerText="End Time"/>
                    <mx:AdvancedDataGridColumn dataField="precooling_time" headerText="Precooling Time"/>
                    <mx:AdvancedDataGridColumn dataField="precooling_temp" headerText="Precooling Temp"/>
                </mx:AdvancedDataGridColumnGroup>
                <mx:AdvancedDataGridColumnGroup headerText="Before Dispatch">
                    <mx:AdvancedDataGridColumn dataField="bd_start_time" headerText="Start Time"/>
                    <mx:AdvancedDataGridColumn dataField="bd_end_time" headerText="End Time"/>
                    <mx:AdvancedDataGridColumn dataField="bd_precooling_time" headerText="Precooling Time"/>
                    <mx:AdvancedDataGridColumn dataField="bd_precooling_temp" headerText="Precooling Temp"/>
                </mx:AdvancedDataGridColumnGroup>
                <mx:AdvancedDataGridColumn dataField="remarks"
                                           headerText="Remarks"/>
            </mx:AdvancedDataGridColumnGroup>
            <mx:AdvancedDataGridColumnGroup headerText="Temperature Compliance">
                <mx:AdvancedDataGridColumn dataField="total_hit" headerText="Total Hit"/>
                <mx:AdvancedDataGridColumn dataField="total_miss" headerText="Total Miss"/>
                <mx:AdvancedDataGridColumn dataField="cold_chain_compliance" headerText="Cold Chain Compliance"/>
                <mx:AdvancedDataGridColumn dataField="average_temp" headerText="Average Temp"/>
            </mx:AdvancedDataGridColumnGroup>
            <mx:AdvancedDataGridColumnGroup headerText="Productivity">
                <mx:AdvancedDataGridColumn dataField="total_drop_points" headerText="Total Drop Points"/>
                <mx:AdvancedDataGridColumn dataField="total_delivery_time" headerText="Total Delivery Time"/>
                <mx:AdvancedDataGridColumn dataField="total_distance" headerText="Total Distance"/>
            </mx:AdvancedDataGridColumnGroup>
            <mx:AdvancedDataGridColumnGroup headerText="Trip Exceptions">
                <mx:AdvancedDataGridColumn dataField="total_doc" headerText="Total DOC"/>
                <mx:AdvancedDataGridColumn dataField="total_eng" headerText="Total ENG"/>
                <mx:AdvancedDataGridColumn dataField="total_fenv" headerText="Total FENV"/>
                <mx:AdvancedDataGridColumn dataField="average_speed" headerText="Average Speed"/>
            </mx:AdvancedDataGridColumnGroup>
        </mx:groupedColumns>
    </mx:AdvancedDataGrid>

谢谢,我真的需要一些帮助。

1 个答案:

答案 0 :(得分:1)

执行此操作的最佳方法是使用Flash Builder的调试模式来准确查看通过哪些数据。

如果命名约定与MXML labelFields不匹配,或者只是重命名labelFields,则可以从SQL查询中设置命名约定。

要转换ResultEvent的结果,通常只需执行以下操作: myArrayCollection = event.result as ArrayCollection;

如果返回的数据是Array,我发现你需要这样做: myArrayCollection = new ArrayCollection(event.result);

希望这有帮助。