flex 简单的增删改查


<?xml version="1.0"?>
<!-- Main application to print a DataGrid control on multiple pages. -->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initData();">
<mx:Script>
<![CDATA[
import mx.printing.*;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.events.ItemClickEvent;


// Declare variables and initialize simple variables.
[Bindable]
public var dgProvider:ArrayCollection;
public var footerHeight:Number=20;
public var prodIndex:Number;
public var prodTotal:Number=0;

// Data initialization.
public function initData():void
{
// Create the data provider for the DataGrid control.
dgProvider=new ArrayCollection;
}

// Fill the dgProvider ArrayCollection with the specified items.
public function setdgProvider(items:int):void
{
prodIndex=1;
dgProvider.removeAll();
for (var z:int=0; z < items; z++)
{
var prod1:Object={};
prod1.Qty=prodIndex * 7;
prod1.Index=prodIndex++;
prodTotal+=prod1.Qty;
dgProvider.addItem(prod1);
}
}

//add function
public function addFunction()
{
var prod2:Object={};
prod2.Qty=11 * 7;
prod2.Index=22;
dgProvider.addItem(prod2);


}

//del function
public function delFunction()
{
if (myDataGrid.selectedItems == null)
return;
var index:int=null;
var seledIndexs:Array=myDataGrid.selectedIndices;
for (var i=0; i < seledIndexs.length; i++)
{
index=seledIndexs[i];
dgProvider.removeItemAt(index);
}
}

//mod function
public function modFunction()
{
var index:int=myDataGrid.selectedIndex;
if (index < 0)
return;
dgProvider.enableAutoUpdate();
var obj:Object=dgProvider.getItemAt(index);
obj.Qty=11111111111111111 * 7;
obj.Index=222222222222222222;
//下面的这句必须要加上,目标是 局部更新页面显示
dgProvider.itemUpdated("", "", "", "");
}
private function clickHandler(event:ItemClickEvent):void
{
if (event.label == "增加")
{
addFunction();
}
else if (event.label == "删除")
{
delFunction();
}
else if (event.label == "修改")
{
modFunction();

}
else if (event.label == "查找")
{
setdgProvider(int(dataItems.text))
}

}
]]>
</mx:Script>

<mx:Panel title="DataGrid 的增删改查 实例"
height="75%"
width="75%"
paddingTop="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10">
<mx:VBox>
<mx:Text width="100%"
color="blue"
text="Specify the number of lines and click Fill Grid first. Then you can click Print."/>
<mx:TextInput id="dataItems"
text="5"/>
<mx:ButtonBar itemClick="clickHandler(event);">
<mx:dataProvider>
<mx:Array>
<mx:String id="add">增加</mx:String>
<mx:String id="del">删除</mx:String>
<mx:String id="mod">修改</mx:String>
<mx:String id="search">查找</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ButtonBar>
<!--
选用AdvancedDataGrid的原因是此控件支持多选。
-->
<mx:AdvancedDataGrid id="myDataGrid"
selectable="true"
selectionMode="multipleRows"
dataProvider="{dgProvider}">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Index"/>
<mx:AdvancedDataGridColumn dataField="Qty"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:VBox>

</mx:Panel>
</mx:Application>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值