首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex list组件增多删除

2013-08-13 
flex list组件增加删除?xml version1.0 encodingutf-8?s:Application xmlns:fxhttp://ns.adobe

flex list组件增加删除
<?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"
  xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <s:layout>
        <s:VerticalLayout verticalAlign="middle" horizontalAlign="center" />
    </s:layout>
   
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
           
            [Bindable]
            private var m:ContextMenu;
           
            [Bindable]
                private var d:ArrayCollection = new ArrayCollection([
                    {id:1,city:"湖南"},
                    {id:1,city:"湖北"},           
                    {id:3,city:"上海"}]);
           
            private function addData():void
            {
                var obj:Object=new Object();
                obj.id=d.length;
                obj.city=t.text;
                d.addItem(obj);
               
                t.text='';
            }
           
            private function deleteData():void{
            d.removeItemAt(lists.selectedIndex);
            }
        ]]>
    </fx:Script>
   
    <fx:Declarations>
    <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
   
    <s:List id="lists" dataProvider="{d}" labelField="city" width="200" height="200"></s:List>
   
    <s:TextInput id="t" width="200"/>
   
    <s:HGroup width="200" height="30" verticalAlign="middle" horizontalAlign="center">
    <s:Button label="添加" enabled="{t.text==''?false:true}" click="addData()" />
    <s:Button label="删除" enabled="{lists.selectedIndex==-1?false:true}" click="deleteData()" />
    </s:HGroup>
</s:Application>

热点排行