0

在单击填充我的数据网格时,我有一个“获取数据”按钮。我想同时用数据网格的列名填充组合框。在生成调用时,结果将存储在最后一个结果中,然后我将其存储到数组中。

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

4

1 回答 1

0

如果我正确理解了您的问题,您只想在获取数据后使用 datagrid 的列名填充您的组合框。如果是这样,您可以使用网格的“列”属性作为组合框的数据提供者。“labelField”属性应设置为“headerText”。清除网格后,将 cb 的 dataprovider 设置为 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>
于 2013-02-15T09:09:58.567 回答