设置comboBox控件的dataProvider属性,可以为其设置其值,例如:
<mx:ComboBox id="typeTime" dataProvider="{type}"/>
<script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public static var type:ArrayCollection= new ArrayCollection([{label:"month", data:1},{label:"year", data:2}]);
]]>
</script>
如果想要获取到dataProvider中设置数组的value值,可以使用comboBox的selectItem属性来获取,例如:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:ComboBox id="timeType" dataProvider="{type}" change="showData()"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public static var type:ArrayCollection= new ArrayCollection([{label:"month", data:1},{label:"year", data:2}]);
public function showData():void
{
trace(timeType.selectedItem.data);
}
]]>
</mx:Script>
</mx:Application>
本文介绍如何在MXML中为ComboBox控件设置dataProvider属性,并通过selectItem属性获取设置数组的value值。代码示例展示了如何定义数组类型、创建数组实例以及在ComboBox的change事件中调用函数来输出所选项的值。
988





