首页  »   Flex

flex 上下左右选择器

网友分享于:2013-11-08  浏览:10次
flex 左右左右选择器
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="350" creationComplete="initApp()" backgroundColor="#FFFFFF" fontSize="12"> 
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.events.ScrollEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent; 
			private function initApp():void{
				left.dataProvider=['北京','上海','江苏','江西','湖南','湖北','四川','西藏','新疆'];
				right.dataProvider=[];
				//'广东','广西','内蒙古','北京','上海','江苏'
			}
			
			private function toRightJustSOSO():void
			{
				
				var selectItems:Array = left.selectedItems;
				var selectIndexs:Array = left.selectedIndices;				
				var bIsThere:Boolean;
				selectIndexs.sort(Array.DESCENDING);
				selectItems.sort(Array.DESCENDING);
				bIsThere=false;
				for( var i:Number = 0 ; i < selectItems.length ; i++ )
				{				
					var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
					for(var j:Number=0; j < rightArray.length ; j++ )   
					{ 
						
						if(selectItems[i].toString()==rightArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(right.dataProvider).addItem(selectItems[i].toString()); 
						ArrayCollection(left.dataProvider).removeItemAt(selectIndexs[i]);
					}
					bIsThere=false;
				}
			}
			
			private function toRightBest():void
			{
				var selectIndexs:Array = left.selectedIndices;				
				var bIsThere:Boolean;
				selectIndexs.sort(Array.DESCENDING);
				bIsThere=false;
				var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
				var leftArray:ArrayCollection=left.dataProvider as ArrayCollection;
				for( var i:Number = 0 ; i < selectIndexs.length ; i++ )
				{				
					
					for(var j:Number=0; j < rightArray.length ; j++ )   
					{ 						
						if(leftArray[selectIndexs[i]].toString()==rightArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(right.dataProvider).addItem(leftArray[selectIndexs[i]].toString()); 
						ArrayCollection(left.dataProvider).removeItemAt(selectIndexs[i]);
					}
					bIsThere=false;
				}
			}
			
			private function toRight():void
			{
				var selectItems:Array = left.selectedItems;
				var selectIndexs:Array = left.selectedIndices;
				var bIsThere:Boolean;
				bIsThere=false;
				for( var i:Number = 0 ; i < selectItems.length ; i++ )
				{				
					var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
					for(var j:Number=0; j < rightArray.length ; j++ )   
					{ 
						
						if(selectItems[i].toString()==rightArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(right.dataProvider).addItem(selectItems[i].toString()); 
						ArrayCollection(left.dataProvider).removeItemAt(selectIndexs[i]);					
					}
					bIsThere=false;
				}
			}
			
			private function toLeft():void
			{
				//var selectItems:Array = right.selectedItems;
				var selectIndexs:Array = right.selectedIndices;
				var bIsThere:Boolean=false;
				
				selectIndexs.sort(Array.DESCENDING);
				var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
				var leftArray:ArrayCollection=left.dataProvider as ArrayCollection;
				
				for( var i:Number = 0 ; i < selectIndexs.length ; i++ )
				{
					var leftArray:ArrayCollection=left.dataProvider as ArrayCollection;
					for(var j:Number=0; j < leftArray.length ; j++ )   
					{ 
						
						if(rightArray[selectIndexs[i]].toString()==leftArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(left.dataProvider).addItem(rightArray[selectIndexs[i]].toString()); 
						ArrayCollection(right.dataProvider).removeItemAt(selectIndexs[i]);
					}
					
				}
			}
			
			private function toRight1():void
			{
				var leftArray:ArrayCollection=left.dataProvider as ArrayCollection;
				var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
				var bIsThere:Boolean=false;				
				for(var i:Number=0; i < leftArray.length ; i++ )
				{
					for(var j:Number=0; j < rightArray.length ; j++ )   
					{ 
						
						if(leftArray[i].toString()==rightArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(right.dataProvider).addItem(leftArray[i].toString()); 
					}
					bIsThere=false;
				}
				
				ArrayCollection(left.dataProvider).removeAll();
				
			}
			
			private function toLeft1():void
			{				
				var leftArray:ArrayCollection=left.dataProvider as ArrayCollection;
				var rightArray:ArrayCollection=right.dataProvider as ArrayCollection;
				var bIsThere:Boolean=false;				
				for(var i:Number=0; i < rightArray.length ; i++ )
				{
					for(var j:Number=0; j < leftArray.length ; j++ )   
					{ 
						
						if(rightArray[i].toString()==leftArray[j].toString()) 
						{							
							bIsThere=true;
						}
					}
					if(!bIsThere)
					{
						ArrayCollection(left.dataProvider).addItem(rightArray[i].toString()); 
					}
					bIsThere=false;
				}
				
				ArrayCollection(right.dataProvider).removeAll();
			}
			
		]]>
	</mx:Script>
	<mx:Panel x="0" y="0" width="450" height="350" layout="absolute" title="左右互选">
		<mx:Label x="7" y="3" text="当前内容"/>
		<mx:List x="7" y="25" id="left" width="168" height="275" allowMultipleSelection="true" 
				 dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" doubleClickEnabled="true" itemDoubleClick="toRight()"> 
		</mx:List>
		<mx:Label x="243" y="3" text="移动内容"/>
		<mx:List x="261" y="32" id="right" width="180" height="272" allowMultipleSelection="true" 
				 dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" doubleClickEnabled="true" itemDoubleClick="toLeft()"> 
		</mx:List>
		<mx:Button x="183" y="73" label="-&gt;&gt;" click="toRight1()" id="bt_allr"/>
		<mx:Button x="183" y="114" label="-&gt;" click="toRightJustSOSO()" id="bt_r"/>
		<mx:Button x="183" y="146" label="&lt;-" click="toLeft()" id="bt_l"/>
		<mx:Button x="183" y="178" label="&lt;&lt;-" click="toLeft1()" id="bt_alll"/>
	</mx:Panel>
</mx:Application>


结果图片如下:

相关解决方案

最新解决方案