Flex 3中,删除List控件中的指定Item
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" fontSize="12" backgroundColor="0xFFFFFF"><mx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] private var _listData:ArrayCollection; private function init():void{ _listData = new ArrayCollection(); var data:Array = new Array(); for(var i:int = 0;i < 10;i++){ var obj:Object = new Object(); obj.label = "列表Item" + i; obj.data = i; data.push( obj ); } _listData.source = data; } private function removeItem(event:MouseEvent):void{ if(myList.selectedItem != null){ for(var i:int = 0;i<_listData.length;i++){ if(_listData[i] == myList.selectedItem){ showMes.text = myList.selectedItem.label + "被删除"; _listData.removeItemAt(i); } } } } ]]></mx:Script> <mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"> <mx:Panel layout="horizontal" width="400" height="300" title="操作列表"> <mx:List id="myList" dataProvider="{_listData}" labelField="label" width="70%"> </mx:List> <mx:VBox width="30%" height="100%"> <mx:Button label="删除选中Item" click="removeItem(event)"/> <mx:Label id="showMes"/> </mx:VBox> </mx:Panel> </mx:HBox></mx:Application>