flex中list控件拖动删除

flex中list控件拖动并删除数据库记录

listdragdelete.mxml

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();" fontSize="14">
    <mx:Script>
            <![CDATA[
            import mx.core.IUIComponent;
            import mx.events.DragEvent;
            import mx.managers.DragManager;

            private function image_dragEnter(evt:DragEvent):void {
                var obj:IUIComponent = IUIComponent(evt.currentTarget);
                DragManager.acceptDragDrop(obj);
    DragManager.showFeedback(DragManager.MOVE);
            }

            private function image_dragDrop(event:DragEvent):void {
               var item:Object = srclist.selectedItem;
               var idx:int = srclist.dataProvider.getItemIndex(item);
               test.text=String(item.data);
               srclist.dataProvider.removeItemAt(idx);
               userRequest.send();
            }

            //定义应用初始化的事件,为相应控件定义数据
           private function initApp():void {
              userRequest.send();
               // destlist.dataProvider =[];
            }
        ]]>
    </mx:Script>
   
   <mx:HTTPService id="userRequest" url="listdelete.php" useProxy="false" method="POST">
      <mx:request xmlns="">
         <delword>{test.text}</delword>
      </mx:request>
   </mx:HTTPService>
   
        <mx:Panel width="274" height="630" layout="absolute">
                <mx:Label text="可供选择的课程" x="10" y="10"/>
                <mx:List id="srclist" dataProvider="{userRequest.lastResult.states.state}"
                    height="397"
                    rollOverColor="#80FF00"
                    allowMultipleSelection="false"
                    dragEnabled="true" width="214" x="10" y="41"/>
                <mx:Label text="拖动要课程到下面的框内即可删除" x="10" y="450"/>
                <mx:List id="destlist"
                    height="86"
                    dragDrop="image_dragDrop(event);"
                    dragEnter="image_dragEnter(event);" 
                    dropEnabled="true" width="214" x="10" y="491"/>
                    <mx:TextInput id="test" text="" x="122" y="446" width="102" visible="false" />
        </mx:Panel>
</mx:Application>

listdelete.php

<?php
 header("content-type:text/html;charset=utf-8");
 $cn=mysql_connect("localhost","root","1*****u");
 $db=mysql_select_db("test");
 mysql_query("SET NAMES utf8");

 if (!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST') {
  if($_POST["delword"]!=""){
 $sql="delete from login where id=".$_POST["delword"]."";
 echo $sql;
 $result=mysql_query($sql);
 }
 }

 $sql="select * from login order by id asc";
 $result=mysql_query($sql);
 $xml_return = "<states>";
 while ($user = mysql_fetch_array($result)){
  $xml_return .="<state><label>".$user["name"]."</label><data>".$user["id"]."</data></state>";
 }
 $xml_return.= "</states>";
 echo $xml_return;
?>

    A+
发布日期:2009年05月13日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: