前台:
function accept(url){
if (endEditing()){
//$('#dg').datagrid('acceptChanges');
//===============开始和后台交互===============================================
var rows = $('#dg').datagrid('getChanges');
var $dg = $('#dg');
alert(rows.length);
if ($dg.datagrid('getChanges').length) {
var inserted = $dg.datagrid('getChanges', "inserted"); //获取添加状态的行
var deleted = $dg.datagrid('getChanges', "deleted");//获取删除状态的行
var updated = $dg.datagrid('getChanges', "updated");//获取修改状态的行
//var effectRow = new Object();
var effectRow = {"updated":updated, "inserted":inserted, "deleted": deleted};
console.log(JSON.stringify(effectRow));
//effectRow["updated"] = updated;
//effectRow["inserted"] = inserted;
//effectRow["deleted"] = deleted;
/* if (updated.length) {
effectRow["updated"] = JSON.stringify(updated);
}
if (inserted.length) {
effectRow["inserted"] = JSON.stringify(inserted);
}
if (deleted.length) {
effectRow["deleted"] = JSON.stringify(deleted);
}*/
//alert(effectRow["updated"]);
//return;
$.ajax({
url: url,
type : "POST",
data: JSON.stringify(effectRow), // 是整个data变json!!!
contentType : "text/plain",
/* data: {
"commitData": JSON.stringify(effectRow)
},*/
dataType: "json",
success: function(response) {
if(response.code == '1') {
$.messager.alert('提示:', '保存成功!');
//var data = response.result;
} else {
//alert('出错了!');
$.messager.alert('提示:', '保存出错了!'+response.result);
}
}
});
/* $.post(url,effectRow, function(rsp) {
debugger;
if(rsp.status){
$.messager.alert("提示", "提交成功!");
$dg.datagrid('acceptChanges');
}
}, "JSON").error(function() {
// $.messager.alert("提示", "提交错误了!");
});*/
}
//================结束和后台交互==============================================
}
}
后台ACTION:
@At("/commitWard")
public Object commitWard(@Param("..")Map paramMap){
HttpServletRequest req = Mvcs.getReq();
System.out.println(Json.toJson(paramMap)); // 打印一下内容
Object result = null; //封装参数
NutMap re = new NutMap();
re.putAll(paramMap);
//System.out.println("params[0]=========="+inserted);
//System.out.println("params[1]=========="+updated);
//System.out.println("params[2]=========="+deleted);
//re.put("inserted", params[0]);
//re.put("updated", params[1]);
//re.put("deleted", params[2]);
result = comServices.ExcuteServices("B01.01.01.02", re);
return result;
}