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

最佳答案

尝试这个:



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

10-11 12:31