0

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

4

1 回答 1

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>
于 2013-09-12T14:08:50.833 回答