Flex中List实现上移下移功能


下面是具体实现代码:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx"  
  5.                 width="100%" height="100%"   
  6.              >  
  7.     <fx:Style source="../../sps/sheet/css/forms.css"/>  
  8.     <s:layout>  
  9.         <s:VerticalLayout/>  
  10.     </s:layout>  
  11.     <fx:Declarations>  
  12.         <!-- 将非可视元素(例如服务、值对象)放在此处 -->  
  13.     </fx:Declarations>  
  14.     <fx:Script>  
  15.         <![CDATA[ 
  16.             import mx.collections.ArrayCollection; 
  17.             import mx.utils.ObjectUtil; 
  18.             private var dp:ArrayCollection=new ArrayCollection([ 
  19.                 {Artist:'Pavement1', Album:'Slanted and Enchanted',  
  20.                     Price:11.99, InStock: true}, 
  21.                 {Artist:'Pavement2', Album:'Crooked Rain, Crooked Rain',  
  22.                     Price:10.99, InStock: false}, 
  23.                 {Artist:'Pavement3', Album:'Wowee Zowee',  
  24.                     Price:12.99, InStock: true}, 
  25.                 {Artist:'Asphalt1', Album:'Brighten the Corners',  
  26.                     Price:11.99, InStock: false}, 
  27.                 {Artist:'Asphalt2', Album:'Terror Twilight',  
  28.                     Price:11.99, InStock: true}, 
  29.                 {Artist:'Asphalt3', Album:'Buildings Meet the Sky',  
  30.                     Price:14.99, InStock: true}, 
  31.                 {Artist:'Other', Album:'Other', Price:5.99, InStock: true} 
  32.             ]); 
  33.              
  34.             private function up():void{ 
  35.                 if(list.selectedIndex>0){ 
  36.                     var i:int=list.selectedIndex; 
  37.                     var tmp:Object=ObjectUtil.copy(list.selectedItem); 
  38.                     var tmpupper:Object=dp.getItemAt(i-1); 
  39.                     dp.setItemAt(tmpupper,i); 
  40.                     dp.setItemAt(tmp,i-1); 
  41.                     list.selectedIndex=i-1; 
  42.                     list.selectedItem=tmp; 
  43.                 } 
  44.             } 
  45.             private function down():void{ 
  46.                 if (list.selectedIndex<dp.length-1){ 
  47.                     var i:int=list.selectedIndex; 
  48.                     var tmp:Object=ObjectUtil.copy(list.selectedItem); 
  49.                     var tmplower:Object=dp.getItemAt(i+1); 
  50.                     dp.setItemAt(tmplower,i); 
  51.                     dp.setItemAt(tmp,i+1); 
  52.                     list.selectedIndex=i+1; 
  53.                     list.selectedItem=tmp; 
  54.                 } 
  55.             } 
  56.  
  57.         ]]>  
  58.     </fx:Script>  
  59.     <s:Group width="100%" height="50%" id="a">  
  60.           
  61.     </s:Group>  
  62.     <s:Group>  
  63.         <s:layout  >  
  64.             <s:VerticalLayout/>  
  65.         </s:layout>  
  66.         <mx:List dataProvider="{dp}" id="list" labelField="Artist"></mx:List>  
  67.         <mx:Button label="UP" click="{up();}" enabled="{list.selectedItem!=null}"/>  
  68.         <mx:Button label="DOWN" click="{down();}" enabled="{list.selectedItem!=null}"/>  
  69.   
  70.     </s:Group>  
  71. </s:Application> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值