我将PHP输出转换为XML标记格式,并且我希望将datafield =' brname '分组为AdvancedDatagrid中的主树或组。
<html>
<head></head>
<body>
<show>
<show_list>
<brname>HONDA</brname>
<dscrpn>CIVIC 2DR</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>GUAM</cr_loc>
<cr_ave>1.33</cr_ave>
</show_list>
<show_list>
<brname>HONDA</brname>
<dscrpn>FIT</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>SAIPAN</cr_loc>
<cr_ave>1.5</cr_ave>
</show_list>
</show>
</body>
</html>
我有HTTPService从PHP输出中获取数据:
<s:HTTPService id="link" url="the php address..." method="GET"/>
我找到了AdvancedDatagrid的示例,但是,数据被声明为一个不适用于我的Arraycollection。 http://kirill-poletaev.blogspot.com/2011/07/advanceddatagrid-in-flex-part-3.html
我试着做类似的代码,只是改变DataProvider来测试概念,如果它可以应用到我想要的输出。
private function init():void{
var myGC:GroupingCollection2 = new GroupingCollection2();
var myG:Grouping = new Grouping();
var myGF:GroupingField = new GroupingField();
myGF.name = "brname";
myG.fields = [myGF];
myGC.grouping = myG;
myGC.source = myGrid.dataProvider;
myGC.refresh();
myGrid.dataProvider = myGC;
}
<mx:AdvancedDataGrid sortExpertMode="true" dataProvider="{link.lastResult.show.show_list}" creationComplete="init()" id="myGrid">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="brname" headerText="Brand" />
<mx:AdvancedDataGridColumn dataField="dscrpn" headerText="Description" />
<mx:AdvancedDataGridColumn dataField="cr_mdl" headerText="Mdel"/>
<mx:AdvancedDataGridColumn dataField="cr_loc" headerText="Loc"/>
<mx:AdvancedDataGridColumn dataField="cr_ave" headerText="Average"/>
</mx:columns>
</mx:AdvancedDataGrid>
以下是我的代码1
的输出brname 的分组似乎没有生效。 对不起,我使用AdvancedDatagrid View有点新鲜。谢谢。
答案 0 :(得分:0)
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<fx:XML xmlns="" id="xml">
<html>
<head></head>
<body>
<show>
<show_list>
<brname>HONDA</brname>
<dscrpn>CIVIC 2DR</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>GUAM</cr_loc>
<cr_ave>1.33</cr_ave>
</show_list>
<show_list>
<brname>HONDA</brname>
<dscrpn>FIT</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>SAIPAN</cr_loc>
<cr_ave>1.5</cr_ave>
</show_list>
<show_list>
<brname>OPEL</brname>
<dscrpn>111</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>111</cr_loc>
<cr_ave>1.5</cr_ave>
</show_list>
<show_list>
<brname>OPEL</brname>
<dscrpn>222</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>222</cr_loc>
<cr_ave>1.3</cr_ave>
</show_list>
</show>
</body>
</html>
</fx:XML>
</fx:Declarations>
<mx:AdvancedDataGrid creationComplete="gc2.refresh()">
<mx:dataProvider>
<mx:GroupingCollection id="gc2" source="{xml.body.show.show_list}" childrenField="undefined">
<mx:Grouping>
<mx:GroupingField name="brname"/>
</mx:Grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="brname" headerText="Brand" />
<mx:AdvancedDataGridColumn dataField="dscrpn" headerText="Description" />
<mx:AdvancedDataGridColumn dataField="cr_mdl" headerText="Model"/>
<mx:AdvancedDataGridColumn dataField="cr_loc" headerText="Loc"/>
<mx:AdvancedDataGridColumn dataField="cr_ave" headerText="Average"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>