日期:2014-05-16  浏览次数:21418 次

jQuery easyui datagrid中调用了acceptChanges后getChecked方法取值为空
使用jquery-easyui在页面新建了一个可编辑datagrid如下:
			jQuery("#repoInDetailGrid").datagrid({
striped: true,
fitColumns: true,
collapsible: false,
singleSelect: true,
checkOnSelect: false,
selectOnCheck: false,
rownumbers: true,
title: "入库明细",
url: "queryProductList.do",
columns: [[{
checkbox: true,
field: "check"
}, {
title: "产品编码",
field: "productCode",
hidden: true
}, {
title: "产品名称",
field: "productName",
width: 100
}, {
title: "规格",
field: "standard",
width: 60
}, {
title: "提货价",
field: "pickPrice",
width: 80,
editor: {
type: "numberbox",
options: {
precision: 2
}
}
}, {
title: "数量",
field: "inAmount",
width: 80,
editor: "numberbox"
}]],
onLoadSuccess: function() {
for (var i = 0; i < jQuery("#repoInDetailGrid").datagrid("getRows").length; i++) {
jQuery("#repoInDetailGrid").datagrid("beginEdit", i);
}
}
});
以下几种测试及结果:
测试1、先选中表格其中的几条记录,执行
jQuery("#repoInDetailGrid").datagrid("acceptChanges");
console.dir(jQuery("#repoInDetailGrid").datagrid("getChecked"));
在console下显示结果为Array[0],但是在页面上checkbox的状态依然是选中的
测试2、先执行
jQuery("#repoInDetailGrid").datagrid("acceptChanges");
然后选中表格中的几条记录,再执行
console.dir(jQuery("#repoInDetailGrid").datagrid("getChecked"));
这时console下显示结果为Array[n](其中n为选中数据条数),这样就有数据了
总结原因:就是datagrid的acceptChanges方法清空了选中的数据,谁有类似情况的解决方法
------解决方案--------------------
我用的1.3.2 也没你说的问题。
------解决方案--------------------
可编辑的执行jQuery("#dg").datagrid("acceptChanges");后获取getChecked确实得不到勾选的数据。。

看了下源代码,应该是easyui的bug,因为可编辑的执行acceptChanges方法后将勾选数据行的datagrid-row-checked给去掉了。。

但是easyui获取勾选的数据行是通过tr是否有datagrid-row-checked这个样式来判断的。。

if(type=="checked"){
return (_70e==1?dc.body1:dc.body2).find(">table>tbody>tr.datagrid-row-checked");
}

改用getSelections来代替