[英]How to populate the combobox with the header Text of the datagrid dynamically in flex 4?
我有一个单击“获取数据”的按钮,单击该按钮可填充我的数据网格。 我想同时用数据网格的列名称填充组合框。 在生成调用时,结果将存储在最后一个结果中,然后我将其存储到array中。
<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"/>
如果我正确理解了您的问题,则只需要在获取数据后用datagrid的列名填充组合框即可。 如果是这样,则可以将网格的“ columns”属性用作组合框的数据提供者。 “ 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.