欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

FLEX下拉多选框

程序员文章站 2022-03-09 13:32:31
...

自己封装的下拉多选:

<?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;

 

相关标签: Flex Adobe XML