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

FLEX list增添数据删除数据

2012-12-18 
FLEX list添加数据删除数据?xml version1.0 encodingutf-8?s:Application xmlns:fxhttp://ns.a

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="800" minHeight="500">
<s:layout>
  <s:BasicLayout/>
</s:layout>
<fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;  
   import mx.controls.Alert;
   import mx.utils.StringUtil;
   import spark.events.IndexChangeEvent;
     
   [Bindable]
   public var memberListData:ArrayCollection=new ArrayCollection([         
    {MemberLevel:"管理员"},
    {MemberLevel:"快计培训"},
    {MemberLevel:"网页设计师"},
    {MemberLevel:"程序员"},
    {MemberLevel:".net开发"},
    {MemberLevel:"C++编程"},
    {MemberLevel:".net开发"},
    {MemberLevel:"管理员"},
    {MemberLevel:"C++编程"},
    {MemberLevel:"程序员"}
   ]);

   protected function button1_clickHandler(event:MouseEvent):void
   {
    this.memberListData.removeItemAt(CouNum);
   }

   private var CouNum:int=-1;
   protected function lst_exam_changeHandler(CountNum:int):void
   {
    CouNum=CountNum;
    this.Del.enabled=true;
   }
  
   protected function AddClick(event:MouseEvent):void
   {
    var obj:Object=new Object();
    obj.MemberLevel=this.PostMember.text;
    if(StringUtil.trim(this.PostMember.text)!=""){
     this.memberListData.addItem(obj);
     this.PostMember.text="";
    }else{
     Alert.show("添加的数据不能为空!");
    }
   
   }

  ]]>
</fx:Script>
<s:BorderContainer width="100%" height="100%" horizontalCenter="0" verticalCenter="0">
  <s:List x="209" y="119" width="234" height="437" dataProvider="{memberListData}" labelField="MemberLevel" id="lst_exam" change="lst_exam_changeHandler(this.lst_exam.selectedIndex)"></s:List>
  <s:Button x="506" y="167" label="删除数据" click="button1_clickHandler(event)" id="Del" enabled="false"/>
  <s:TextInput x="506" y="243" id="PostMember"/>
  <s:Button x="642" y="243" label="添加数据" click="AddClick(event)"/>
</s:BorderContainer>

</s:Application>
FROM:http://blog.sina.com.cn/s/blog_62b37fda0100yfoi.html

热点排行