您的位置:首页 > 其它

DataGrid更新数据时的一系列问题的解决

2011-04-28 21:28 267 查看
【问题描述】

一个表格,里面是员工的信息,可以通过update操作更新员工信息,但这一操作需要在表格下的表单中进行。


如上图所示,必须先按下update,然后在红色方框的表单中修改。现在希望能直接在表格里修改。
【方法】
1. 将DataGrid设置为editable
2. 增加事件itemEditEnd
3. 为事件itemEditEnd添加响应函数
protected function empDg_itemEditEndHandler(event:DataGridEvent):void
{
employee[event.dataField] =	(empDg.itemEditorInstance as mx.controls.TextInput).text;
employeeService.updateEmployee(employee);
}

其中employee[event.dataField] = (empDg.itemEditorInstance as mx.controls.TextInput).text;修改的是前端
employeeService.updateEmployee(employee);修改的是后端
4. 运行程序,可以直接在表格中修改了。


改成



【仍然存在的问题】
页面刷新后,smith_test又变回了smith
【分析】
页面刷新后,数据恢复到未修改的状态,说明后来的数据没有修改成功
【测试过程】
1. 打开Network Monitor,发现有2个响应



在DataGrid中修改后发现响应没有增加,说明employeeService.updateEmployee(employee);
这一句并没有被调用。
2. 代码定位到事件响应定义处,发现
<mx:DataGrid x="36" y="167" id="empDg" creationComplete="empDg_creationCompleteHandler(event)" dataProvider="{getEmployeesResult.lastResult}" width="751" includeIn="EmployeeAdd,EmployeeDetail,EmployeeUpdate,Employees" change.Employees="empDg_changeHandler(event)" x.Employees="36" y.Employees="148" x.EmployeeDetail="36" y.EmployeeDetail="151" x.EmployeeAdd="36" y.EmployeeAdd="151" x.EmployeeUpdate="36" y.EmployeeUpdate="151" editable="true" itemEditEnd.Employees="empDg_itemEditEndHandler(event)">
【原因】 原来是此函数仅在状态Employees中才响应,而编辑DataGrid时程序已经转入了EmployeeDetail状态
【修改】
itemEditEnd="empDg_itemEditEndHandler(event)"

测试修改后刷新页面,问题终于解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: