浏览 6985 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-02-24
最后修改:2010-02-24
单击DataGrid单元格编辑出现ComboBox,选择相应的值,要使数据写入数据库就要调用DataGrid的itemEditEnd事件,itemEditEnd事件是在离开编辑单元格后触发的. itemEditEnd事件调用的方法 private function updatePro(event:DataGridEvent):void{ var dataField:String = event.dataField;//获取绑定字段的名称 var proId:String = mydate.selectedItem.proId;//获取id if(dataField=="completePreStr"){ var newData:String = ""; try{ newData = ComboBox(event.currentTarget.itemEditorInstance).selectedLabel//获取编辑后的新值 }catch(errObject:Error){ } //判断为null的情况,否则很容易出现TypeError: Error #1009: 无法访问空对象引用的属性或方法 if(newData!=null){ myProService.updateCompletePreStr(proId,newData);//调用更新方法 } } } 全部源码: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="white" creationComplete="init2();init();" height="1332" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FCFCFC, #040303]" xmlns:local="*" xmlns:ns1="com.esria.samples.dashboard.view.*"> <mx:Script> <![CDATA[ import mx.controls.List; import mx.collections.ArrayCollection; import mx.events.CuePointEvent; import mx.events.VideoEvent; import mx.controls.Alert; import mx.rpc.events.ResultEvent; import mx.events.DataGridEvent; [Bindable] private var FLV_URL:String = "zhajm_126296095230hd.flv"; [Bindable] private var userInfoList:ArrayCollection; [Bindable] private var userInfo:Object; [Bindable] public var cards:ArrayCollection; /** * Initialize the ArrayCollection object. */ private function init():void { department.getDepartment(); } private function init2():void { myservice.getProInfo("",""); } public function resultHandler(result:ResultEvent):void{ userInfoList = result.result as ArrayCollection; userInfo = userInfoList.getItemAt(0); //Alert.show(userInfo.userName); } private function changeHandler(event:Event):void { myservice.getProInfo(departmentId.text,pageNum.text); } private function closeHandler(result:ResultEvent):void { cards = result.result as ArrayCollection; } private function formatDate(item:Object,column:DataGridColumn):String{ if (item[column.dataField] == null) { return "-"; } return FD.format(item[column.dataField]); } private function formatPre(item:Object,column:DataGridColumn):String{ if (item[column.dataField] == null) { return "-"; } if (item[column.dataField] == 1) { return "模型"; } if (item[column.dataField] == 2) { return "预演"; } if (item[column.dataField] == 3) { return "小样"; } if (item[column.dataField] == 4) { return "渲染"; } if (item[column.dataField] == 5) { return "后期"; } return item[column.dataField]; } private function updatePro(event:DataGridEvent):void{ var dataField:String = event.dataField;//获取绑定字段的名称 var proId:String = mydate.selectedItem.proId;//获取id if(dataField=="completePreStr"){ var newData:String = ""; try{ newData = ComboBox(event.currentTarget.itemEditorInstance).selectedLabel//获取编辑后的新值 }catch(errObject:Error){ } //判断为null的情况,否则很容易出现TypeError: Error #1009: 无法访问空对象引用的属性或方法 if(newData!=null){ myProService.updateCompletePreStr(proId,newData);//调用更新方法 } } } ]]> </mx:Script> <mx:Text fontFamily="微软雅黑" fontSize="12" text="项目名称" x="304" y="10"/> <mx:Text fontFamily="微软雅黑" fontSize="12" text="所属部门" x="85" y="9"/> <mx:ComboBox id="departmentId" dataProvider="{cards}" x="146" width="150" color="0x000000" labelField="departmentName" y="10" change="changeHandler(event)" enabled="true" editable="true"/> <mx:TextInput width="150" id="pageNum" x="365" y="11" change="changeHandler(event)"/> <mx:RemoteObject id="myservice" destination="provinceService" result="resultHandler(event)"/> <mx:RemoteObject id="myProService" destination="provinceService"/> <mx:DateFormatter id="FD" formatString="YYYY年MM月DD日" /> <mx:Array id="coffeeArray"> <mx:Object label="readsea" data="readsea" /> <mx:Object label="readsea1" data="readsea11" /> <mx:Object label="readsea2" data="readsea22" /> <mx:Object label="readsea3" data="readsea33" /> </mx:Array> <mx:DataGrid id="mydate" dataProvider="{userInfoList}" height="600" width="100%" fontFamily="微软雅黑" fontSize="12" y="40" editable="true" itemEditEnd="updatePro(event)"> <mx:columns> <mx:DataGridColumn dataField="proId" visible="false" id="proId" editable="false"/> <mx:DataGridColumn headerText="项目名称" dataField="proName" editable="false"/> <mx:DataGridColumn headerText="客户名称" dataField="customName" editable="false"/> <mx:DataGridColumn headerText="项目负责人" dataField="userNamePrincipal" editable="false"/> <mx:DataGridColumn headerText="类别" dataField="type" editable="false"/> <mx:DataGridColumn headerText="状态" dataField="state" editable="false"/> <mx:DataGridColumn headerText="开始日期" dataField="beginTime" labelFunction="formatDate" editable="false"/> <mx:DataGridColumn headerText="结束日期" dataField="completeTime" labelFunction="formatDate" editable="false"/> <mx:DataGridColumn headerText="实际时长" dataField="atl" editable="false"/> <mx:DataGridColumn headerText="总预算" dataField="forecastCost" editable="true"/> <mx:DataGridColumn headerText="项目进度" dataField="completePreStr" editorDataField="value" id="jindu" editable="true" > <mx:itemEditor> <mx:Component> <mx:ComboBox editable="true" width="100"> <mx:dataProvider> <mx:String>模型</mx:String> <mx:String>预演</mx:String> <mx:String>小样</mx:String> <mx:String>渲染</mx:String> <mx:String>后期</mx:String> </mx:dataProvider> </mx:ComboBox> </mx:Component> </mx:itemEditor> </mx:DataGridColumn> <mx:DataGridColumn headerText="工作量" dataField="commision" editable="false"/> <mx:DataGridColumn headerText="任务数量" dataField="taskNum" editable="false"/> </mx:columns> </mx:DataGrid> <mx:Label text="{mydate.selectedItem.proId}" id="huahua"/> <mx:RemoteObject id="department" destination="myObject" result="closeHandler(event)"/> </mx:Application>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |