2013-09-11 60 views
0

我把我的PHP輸出轉換爲XML標籤格式,我想將我的PHP輸出分組爲我的AdvancedDatagrid中的主樹或組。將一個數據字段從PHP輸出數據分組到一個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視圖有點新。謝謝。

回答

0

試試這個:

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> 
相關問題