加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex中List实现上移下移功能

发布时间:2020-12-15 04:32:27 所属栏目:百科 来源:网络整理
导读:下面是具体实现代码: [html] view plain copy ? xml ? version = "1.0" ? encoding = "utf-8" ? ?? s:Application ? xmlns:fx = "http://ns.adobe.com/mxml/2009" ??? ??????????????? xmlns:s = "library://ns.adobe.com/flex/spark" ??? ???????????????


下面是具体实现代码:

[html] view plain copy
  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,?
  25. ????????????????{Artist:'Asphalt1',?Album:'Brighten?the?Corners',?
  26. ????????????????{Artist:'Asphalt2',?Album:'Terror?Twilight',?
  27. ????????????????{Artist:'Asphalt3',?Album:'Buildings?Meet?the?Sky',??
  28. ????????????????????Price:14.99,?
  29. ????????????????{Artist:'Other',?Album:'Other',?Price:5.99,?InStock:?true}?
  30. ????????????]);?
  31. ?????????????
  32. ????????????private?function?up():void{?
  33. ????????????????if(list.selectedIndex>0){?
  34. ????????????????????var?i:int=list.selectedIndex;?
  35. ????????????????????var?tmp:Object=ObjectUtil.copy(list.selectedItem);?
  36. ????????????????????var?tmpupper:Object=dp.getItemAt(i-1);?
  37. ????????????????????dp.setItemAt(tmpupper,i);?
  38. ????????????????????dp.setItemAt(tmp,i-1);?
  39. ????????????????????list.selectedIndex=i-1;?
  40. ????????????????????list.selectedItem=tmp;?
  41. ????????????????}?
  42. ????????????}?
  43. ????????????private?function?down():void{?
  44. ????????????????if?(list.selectedIndex<dp.length-1){?
  45. ????????????????????var?i:int=list.selectedIndex;?
  46. ????????????????????var?tmp:Object=ObjectUtil.copy(list.selectedItem);?
  47. ????????????????????var?tmplower:Object=dp.getItemAt(i+1);?
  48. ????????????????????dp.setItemAt(tmplower,i);?
  49. ????????????????????dp.setItemAt(tmp,i+1);?
  50. ????????????????????list.selectedIndex=i+1;?
  51. ????????????????????list.selectedItem=tmp;?
  52. ????????????????}?
  53. ????????????}?
  54. ?
  55. ????????]]>??
  56. ????</fx:Script>??
  57. ????<s:Group?width="100%"?height="50%"?id="a">??
  58. ??????????
  59. ????</s:Group>??
  60. ????<s:Group>??
  61. ????????<s:layout??>??
  62. ????????????<s:VerticalLayout/>??
  63. ????????</s:layout>??
  64. ????????<mx:List?dataProvider="{dp}"?id="list"?labelField="Artist"></mx:List>??
  65. ????????<mx:Button?label="UP"?click="{up();}"?enabled="{list.selectedItem!=null}"/>??
  66. ????????<mx:Button?label="DOWN"?click="{down();}"?enabled="{list.selectedItem!=null}"/>??
  67. ??
  68. ????</s:Group>??
  69. </s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读