gpt4 book ai didi

php - 将 PHP 输出数据中的数据字段分组到 AdvancedDatagrid

转载 作者:行者123 更新时间:2023-11-30 01:19:17 25 4
gpt4 key购买 nike

我将 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 有点陌生。谢谢。

最佳答案

试试这个:

enter image description here

<?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>

关于php - 将 PHP 输出数据中的数据字段分组到 AdvancedDatagrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com