DataGrid删除

http://www.iflex4.com/Flex3/Flex3Advanced/2011/0310/173.html

原代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical" fontSize="12" verticalAlign="middle" backgroundColor="white">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
         import mx.events.ItemClickEvent;
            [Bindable]        
            public var users:ArrayCollection =new ArrayCollection(
               [{ida:1,username:"aaa", dept:"开发部"},     
                        {ida:2,username:"bbb", dept:"产品部"},     
                      {ida:3,username:"ccc", dept:"开发部"},                        
                   {ida:4,username:"ddd", dept:"产品部"}]);  
            private function shanchu(evt:Object):ArrayCollection{
                var item:Object = dataGrid.selectedItem;
                var idx:int = users.getItemIndex(item);
                users.removeItemAt(idx);
                return users;
            }
        ]]>
    </mx:Script>
    <mx:Panel title="单击选中的元素并删除">
        <mx:DataGrid id="dataGrid"
                dataProvider="{users}" itemClick="{shanchu(dataGrid.selectedItem)}">
            <mx:columns>
                <mx:DataGridColumn dataField="ida"
                        headerText="ida" />
                <mx:DataGridColumn dataField="username"
                        headerText="username" />
                <mx:DataGridColumn dataField="dept"
                        headerText="dept" />
                <mx:DataGridColumn dataField="c4"
                        headerText="Column 4" />
            </mx:columns>
        </mx:DataGrid>
    </mx:Panel>
</mx:Application>


你可能感兴趣的:(html,xml,Flex,Flash)