datagrid根据列值(True,False)设置checkbox的绑定状态
代码示例
function AuthoritySetting() {
var row = $(
'#dg').datagrid(
'getSelected');
if (row) {
$(
'#dlgAuthoritySetting').dialog(
'open');
$(
'#tbxRoleCode').textbox(
'setValue', row.角色代码);
$(
'#tbxRoleName').textbox(
'setValue', row.角色名称);
$.ajax({
contentType:
"application/x-www-form-urlencoded; charset=UTF-8",
url:
"../../Controller/Interface/ComAuthority.ashx?Action=BindRole",
type:
"get",
data: {
"roleCode":
encodeURIComponent($(
'#tbxRoleCode').textbox(
'getText')),
},
dataType:
"json",
success:
function (data) {
$(
"#dgrole").datagrid(
"options").pageNumber =
1;
$(
"#dgrole").datagrid(
"loadData", data);
if (data) {
$.each(data.rows,
function (index, item) {
if (item.checked ==
"True") {
$(
'#dgrole').datagrid(
'checkRow', index);
}
else {
$(
'#dgrole').datagrid(
'uncheckRow', index);
}
});
}
}
});
}
}
核心部分
if (data) {
$.each(data.rows,
function (index, item) {
if (item.checked ==
"True") {
$(
'#dgrole').datagrid(
'checkRow', index);
}
else {
$(
'#dgrole').datagrid(
'uncheckRow', index);
}
});
}
item.checked中的checked并不是一个系统属性,是data中的一个叫checked的列,我们在这个列写true或者false,抛给datagrid显示成checkbox的勾中或者不勾中效果。