FLEX下拉多选框

自己封装的下拉多选:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import mx.controls.List;
			import mx.collections.ArrayCollection;
			import CheckBoxItemRenderer;
			
			private var _seletedItems:Array;
			private var list:List;
			public var comboData:ArrayCollection;
			
			private function init():void
			{
				this.addEventListener(MouseEvent.MOUSE_OVER, addPopUp);
				createCombo();
			}
			
			public function set seletedItems(value:Array):void
			{
				_seletedItems = value;
				
				if(list)
				{
					var items:ArrayCollection = list.dataProvider as ArrayCollection;
					for each(var obj:Object in items)
					{
						if(_seletedItems.indexOf(obj["value"]) != -1)
						{
							obj["checked"] = true;
						}
						else
						{
							obj["checked"] = false;
						}
					}
					showSeleted();
				}
			}
			
			public function get seletedItems():Array
			{
				if(list)
				{
					var items:ArrayCollection = list.dataProvider as ArrayCollection;
					var seletedItems:Array = [];
					for each(var obj:Object in items)
					{
						if(obj["checked"] && "" != obj["value"])
						{
							seletedItems.push(obj["value"]);
						}
					}
					_seletedItems = seletedItems;
				}
				return _seletedItems;
			}
			
			private function createCombo():void
			{
				if(null != comboData)
				{
					var dataSource:ArrayCollection = new ArrayCollection();
					for each(var item:Object in comboData)
					{
						dataSource.addItem({label:item.label,value:item.data,checked:false});
					}
					list = new List();
					list.dataProvider = dataSource;
					list.itemRenderer = new ClassFactory(CheckBoxItemRenderer);
					list.rowCount = 5;
					list.width = width;
					addPopUp();
					showSeleted();
				}
			}
			
			private function showSeleted():void
			{
				if(list)
				{
					var items:ArrayCollection = list.dataProvider as ArrayCollection;
					var seletedItems:Array = [];
					for each(var obj:Object in items)
					{
						if(obj["checked"] && "" != obj["value"])
						{
							seletedItems.push(obj["label"]);
						}
					}
					multiCombo.label = seletedItems.length > 0?seletedItems.toString():"请选择";
					multiCombo.toolTip = multiCombo.label;
				}
			}
			
			private function addPopUp(e:MouseEvent=null):void
			{
				if(null == multiCombo.popUp && null != list)
				{
					var can:Canvas = new Canvas();
					can.addChild(list);
					multiCombo.popUp = can;
				}
			}
		]]>
	</mx:Script>
	
	<mx:PopUpButton id="multiCombo" label="请选择" width="{width}" textAlign="left" fontWeight="normal"
		openAlways="true" close="showSeleted()"/>
</mx:Canvas>

 

 

 

下面在别的地方引入:

<common:MultiComboBox id="multiCombo2" width="150" comboData="{mnpStatus}"/>

 comboData为数据源

取值:

var arraySelected:Array = multiCombo.seletedItems as Array;

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值