2013-02-13 50 views
0

我有一個按鈕「獲取數據」點擊我的數據網格填充。我想用數據網格的列名同時填充組合框。在生成調用時,結果存儲在最後的結果中,然後我將其存儲到數組中。如何使用標題填充組合框的文本DataGrid的文本在Flex 4中動態顯示?

<fx:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 
     import mx.controls.Alert; 
     import mx.events.FlexEvent; 
     import mx.events.ListEvent; 
     import mx.rpc.events.ResultEvent; 

     import services.ServiceManager; 

     import spark.events.IndexChangeEvent; 


     [Bindable] public var ArrColl_selectOptionComboBox:ArrayCollection = new ArrayCollection; 
     [Bindable] public var SelectOption:ArrayCollection = new ArrayCollection; 

     [Bindable] public var mainArrColl:ArrayCollection = new ArrayCollection; 
     [Bindable] public var DGDataProvider:ArrayCollection = new ArrayCollection; 
     [Bindable] public var DGDataProvider1:ArrayCollection = new ArrayCollection; 

     public function clear():void 
     { 
      DGDataProvider = new ArrayCollection; 
     } 

     //clicking on the Get Data button to retrieve from the Jiraissue 
     protected function button_clickHandler(event:MouseEvent):void 
     { 
      getAllJiraissueResult2.token=jiraissueService1.getAllJiraissue(); 


     } 

     protected function getAllJiraissueResult2_resultHandler(event:ResultEvent):void 
     { 
      mainArrColl = getAllJiraissueResult2.lastResult as ArrayCollection; 
      DGDataProvider = mainArrColl; 



     } 









    //protected function Combobox_Option_changeHandler(event:ListEvent):void 
     //{ 

       //myLabel.text = "You selected: " + ComboBox(event.target).selectedItem.label; 

        //Value.prompt="Select Value"; 
        //Value.selectedIndex=-1; // reset so prompt shows 





     //} 

     ]]> 

</fx:Script> 

<fx:Declarations> 
    <jiraissueservice1:JiraissueService1 id="jiraissueService1" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/> 
    <s:CallResponder id="getAllJiraissueResult2" result="getAllJiraissueResult2_resultHandler(event)"/> 

    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<s:Button x="59" y="49" label="GET DATA" id="button" click="button_clickHandler(event)"/> 
<mx:DataGrid x="60" y="299" width="800" id="dataGrid" dataProvider="{DGDataProvider}"> 
    <mx:columns> 

     <mx:DataGridColumn headerText="pkey" dataField="pkey"/> 
     <mx:DataGridColumn headerText="PROJECT" dataField="pname"/> 
     <mx:DataGridColumn headerText="CREATED" dataField="CREATED"/> 
     <mx:DataGridColumn headerText="defectType" dataField="stringvalue"/> 
     <mx:DataGridColumn headerText="Reporter" dataField="REPORTER"/> 
     <mx:DataGridColumn headerText="ASSIGNEE" dataField="ASSIGNEE"/> 
     <mx:DataGridColumn headerText="SLA" dataField="SLA"/> 

    </mx:columns> 
</mx:DataGrid> 


<s:Button x="214" y="49" label="RESET" click="clear()"/> 
<s:Button x="557" y="168" label="Button"/> 

<mx:ComboBox id="Combobox_Option" width="201" dataProvider="{SelectOption}" labelField="label" 
       prompt="Select Option" 
       x="59" y="169"/> 
<mx:ComboBox id="Value" width="201" labelField="label" 
       prompt="Select Value" dataProvider="{DGDataProvider1}" 
       x="308" y="169"/> 
<s:Label id="myLabel" text="You selected:" fontWeight="bold" x="59" y="275"/> 

+0

指定代碼,請 – bsiamionau 2013-02-13 07:49:25

+0

請儘快回覆 – user2067398 2013-02-13 12:52:56

回答

0

如果我明白你的問題正確,你只是想獲取數據後,填充DataGrid的列名的組合框。如果是這樣,您可以使用網格的「列」屬性作爲組合框的數據提供者。 「labelField」屬性應該設置爲「headerText」。清除網格後,將cb的數據提供者設置爲null。

下面是一個簡單的代碼:

<?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:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 
     import mx.events.CollectionEvent; 

     [Bindable]private var dp:ArrayCollection = new ArrayCollection([ 
      {artist:"Pavement",   album:"Slanted and Enchanted", year:"2010", price:39.1}, 
      {artist:"ABBA",    album:"Ring Ring",    year:"1973", price:45.2}, 
      {artist:"The Betles",  album:"Please Please Me",  year:"1963", price:29.1}]); 

     private function onBtnLoad():void 
     { 
      myGrid.dataProvider = dp; 

      cbCategories.dataProvider = myGrid.columns; 
      cbCategories.labelField = "headerText"; 
     } 

     private function onBtnReset():void 
     { 
      myGrid.dataProvider = null; 

      cbCategories.selectedIndex = -1; 
      cbCategories.dataProvider = null; 
     } 

    ]]> 
</fx:Script> 


<s:VGroup x="70" y="50"> 
    <s:DataGrid id="myGrid" width="420" height="100" > 
     <s:columns> 
      <s:ArrayList> 
       <s:GridColumn dataField="artist" headerText="Artist's name" width="150"/> 
       <s:GridColumn dataField="album"  headerText="Album"/> 
       <s:GridColumn dataField="year"  headerText="Year" width="50"/> 
       <s:GridColumn dataField="price"  headerText="Price" width="50"/> 
      </s:ArrayList> 
     </s:columns>  
    </s:DataGrid> 

    <s:HGroup> 
     <s:Button id="btnLoad" label="Load Data" click="onBtnLoad()"/> 
     <s:Button id="btnReset" label="Reset" click="onBtnReset()"/> 
    </s:HGroup> 

    <s:HGroup verticalAlign="bottom"> 
     <s:Label text="Categories:" width="70"/> 
     <s:ComboBox id="cbCategories"/> 
    </s:HGroup> 
</s:VGroup> 

</s:Application>