问题:Flex / Flash4客户端(使用FlashBuilder4构建)完全按原样显示从服务器发送的xml - datagrid保留xml的格式。我需要datagrid来解析输入并将数据放在datagrid的正确行和列中。
flow:单击树中的日期,它以xml格式向服务器请求批处理信息。使用CallResponder我然后更新datagrid的dataProvider。
[代码]
<fx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]public var selectedTreeNode:XML;
public function taskTreeChanged(event:Event):void {
selectedTreeNode=Tree(event.target).selectedItem as XML;
var searchHubId:String = selectedTreeNode.@hub;
var searchDate:String = selectedTreeNode.@lbl;
if((searchHubId == "") || (searchDate == "")){
return;
}
findShipmentBatches(searchDate,searchHubId);
}
protected function findShipmentBatches(searchDate:String, searchHubId:String):void{
findShipmentBatchesResult.token = actWs.findShipmentBatches(searchDate, searchHubId);
}
protected function updateBatchDataGridDP():void{
task_list_dg.dataProvider = findShipmentBatchesResult.lastResult;
}
]]>
</fx:Script>
<fx:Declarations>
<actws:ActWs id="actWs" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="findShipmentBatchesResult" result="updateBatchDataGridDP()"/>
</fx:Declarations>
<mx:AdvancedDataGrid id="task_list_dg" width="100%" height="95%" paddingLeft="0" paddingTop="0" paddingBottom="0">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Receiving date" dataField="rd"/>
<mx:AdvancedDataGridColumn headerText="Msg type" dataField="mt"/>
<mx:AdvancedDataGridColumn headerText="SSD" dataField="ssd"/>
<mx:AdvancedDataGridColumn headerText="Shipping site" dataField="sss"/>
<mx:AdvancedDataGridColumn headerText="File name" dataField="fn"/>
<mx:AdvancedDataGridColumn headerText="Batch number" dataField="bn"/>
</mx:columns>
</mx:AdvancedDataGrid>
//xml example from server
<batches>
<batch>
<rd>2010-04-23 16:31:00.0</rd>
<mt>SC1REVISION01</mt>
<ssd>2010-02-18 00:00:00.0</ssd>
<sss>100000009</sss>
<fn>Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv</fn>
<bn>10041</bn>
</batch>
<batches>
[/代码]
并且xml几乎完全按照上面示例中的datagrid列显示...
感谢您的协助。
答案 0 :(得分:0)
我使用简单的xml文字尝试了简化版本的样本,它对我来说很好..
这就是我所拥有的
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function onCreationCompleteHandler(event:FlexEvent):void
{
task_list_dg.dataProvider = data..batch;
}
private var data:XML = //xml example from server
<batches>
<batch>
<rd>2010-04-23 16:31:00.0</rd>
<mt>SC1REVISION01</mt>
<ssd>2010-02-18 00:00:00.0</ssd>
<sss>100000009</sss>
<fn>Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv</fn>
<bn>10041</bn>
</batch>
</batches>;
]]>
</fx:Script>
<mx:AdvancedDataGrid id="task_list_dg" width="100%" height="95%" paddingLeft="0" paddingTop="0" paddingBottom="0">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Receiving date" dataField="rd"/>
<mx:AdvancedDataGridColumn headerText="Msg type" dataField="mt"/>
<mx:AdvancedDataGridColumn headerText="SSD" dataField="ssd"/>
<mx:AdvancedDataGridColumn headerText="Shipping site" dataField="sss"/>
<mx:AdvancedDataGridColumn headerText="File name" dataField="fn"/>
<mx:AdvancedDataGridColumn headerText="Batch number" dataField="bn"/>
</mx:columns>
</mx:AdvancedDataGrid>
您确定您的数据是以您建议的格式到达吗? (查看FB中的“数据/服务”选项卡)
你是什么意思“显示从服务器发送的xml完全一样 - datagrid保持xml的格式”?它会在网格单元格中转储xml内容吗?
修改:您是否尝试过这样做?
protected function updateBatchDataGridDP():void{
task_list_dg.dataProvider = findShipmentBatchesResult.lastResult..batch;
}
答案 1 :(得分:0)
不得不求助于这种怪物----&gt;有更好的方法???
protected function updateBatchDataGridDP():void{
var batches:XML = new XML(findShipmentBatchesResult.lastResult);
task_list_dg.dataProvider = batches.batch;
var task_list_col1:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col1.dataField = "@rd";
task_list_col1.headerText = "Receiving date";
var task_list_col2:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col2.dataField = "@mt";
task_list_col2.headerText = "Msg type";
var task_list_col3:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col3.dataField = "@ssd";
task_list_col3.headerText = "SSD";
var task_list_col4:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col4.dataField = "@sss";
task_list_col4.headerText = "Shipping site";
task_list_status.text = batches.batch.@sss;
var task_list_col5:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col5.dataField = "@fn";
task_list_col5.headerText = "File name";
var task_list_col6:AdvancedDataGridColumn = new AdvancedDataGridColumn();
task_list_col6.dataField = "@bn";
task_list_col6.headerText = "Batch number";
var myColumns:Array = new Array();
myColumns.push(task_list_col1);
myColumns.push(task_list_col2);
myColumns.push(task_list_col3);
myColumns.push(task_list_col4);
myColumns.push(task_list_col5);
myColumns.push(task_list_col6);
task_list_dg.columns = myColumns;
}
使用这个xml结构:
<batches>
<batch rd="2010-04-23 16:31:00.0" mt="SC1REVISION01" ssd="2010-02-18 00:00:00.0" sss="Quanta" fn="Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv" bn="SHA201004230033" />
<batch rd="2010-04-23 16:32:14.0" mt="SC1" ssd="2010-02-11 00:00:00.0" sss="Quanta" fn="DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100211.csv" bn="SHA201004230043" />
<batch rd="2010-04-23 16:35:51.0" mt="PRESHIP" ssd="2010-02-15 00:00:00.0" sss="Quanta" fn="DF-Ocean-PRESHIPSUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100215.csv" bn="SHA201004230045" />
</batches>