浏览 4971 次
锁定老帖子 主题:flex 左右左右选择器
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-08-10
<?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="->>" click="toRight1()" id="bt_allr"/> <mx:Button x="183" y="114" label="->" click="toRightJustSOSO()" id="bt_r"/> <mx:Button x="183" y="146" label="<-" click="toLeft()" id="bt_l"/> <mx:Button x="183" y="178" label="<<-" click="toLeft1()" id="bt_alll"/> </mx:Panel> </mx:Application> 结果图片如下: 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-10-08
想复杂了。
|
|
返回顶楼 | |
发表时间:2012-04-19
那你觉得呢? 怎么才简单
|
|
返回顶楼 | |