flex DataGrid编辑单元格并获取新的值
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
<mx:Panel width="458" height="313" layout="absolute">
<mx:Label id="lbl" x="19" y="10" text="" width="171" height="20"/>
<mx:DataGrid id="dg" x="19" y="58" dataProvider="{arr}" editable="true" itemEditEnd="editHandle(event)"
horizontalGridLines="true" horizontalGridLineColor="#B9F2C9" verticalGridLineColor="#B9F2C9">
<mx:columns>
<mx:DataGridColumn headerText="year" dataField="year" editable="false"/>
<mx:DataGridColumn headerText="city" dataField="city" editable="false"/>
<mx:DataGridColumn headerText="provice" dataField="provice" editable="false" sortable="false"/>
<mx:DataGridColumn headerText="total" dataField="total"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
<mx:Script>
<!--[CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.events.DataGridEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable]
private var arr:ArrayCollection=new ArrayCollection([
{year:2009,city:"Shanghai",provice:"上海",total:580000},
{year:2009,city:"Beijing",provice:"河北省",total:7852020},
{year:2009,city:"Nanjing",provice:"江苏省",total:895145},
{year:2009,city:"Hangzhou",provice:"浙江省",total:4132415}]);
private function editHandle(event:DataGridEvent):void{
if(event.dataField=="total"){
var cols:DataGridColumn=dg.columns[event.columnIndex];
///编辑前的值,没用到,只是想获得一下
var s:String=event.itemRenderer.data.total;
//编辑后新的值
var newValue:String=dg.itemEditorInstance[cols.editorDataField];
var num:Number=Number(tt);
if(isNaN(num)){
event.preventDefault();//恢复本来数据
lbl.text="this is not num!";
}else{
lbl.text=tt;
/*=======操作数据和数据库打交道=========*/
/*省略*/
}
}
}
相关文档:
1、arraycollection转化为xml,代码如下:
//动态生成树形结构
public static function flatArrayToXML(arr:Object,rootname:String=null,nodename:String=null, outputString:Boolean=false):Object{
if (arr is Array){
......
在同一个Application中动态切换主题,这里采用的是动态引用不同的CSS文件。
具体步骤如下:
1)创建CSS文件
skyTheme.css
/* CSS file */
.backgroudSkin
{
&nbs ......
Flex应用的根是SystemManger,它是flash.display.MovieClip的子类,一个Flash Player显示对象类型。SystemManager有两个帧,第一帧是用来显示应用载入的进度指示,这个帧是轻量的,所以它几乎能立即下载和运行。第二帧便是应用本身。当一个Flex应用的SystemManager实例进入到第二帧,它创建一个主应用的实例。SystemManager ......
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XML id="xmlSource">
<node label="grandFather" state="unchecked">
<node label="Father" state="un ......