【发布时间】:2019-11-30 11:54:06
【问题描述】:
我正在使用 mleibman/SlickGrid 并且有复选框 (isChecked) 列,
var columns = [
{ id: "tagID", name: "#", field: "tagID", behavior: "select", cssClass: "cell-selection", width: 40, cannotTriggerInsert: true, resizable: false, selectable: false, excludeFromColumnPicker: true },
{ id: "isChecked", name: "isChecked", field: "isChecked", width: 80, minWidth: 20, maxWidth: 80, cssClass: "slick-cell-check", formatter: Slick.Formatters.Checkbox, editor: Slick.Editors.Checkbox, sortable: true },
{ id: "tagName", name: "tagName", field: "tagName", width: 90, minWidth: 120, cssClass: "cell-title", sortable: true },
{ id: "description", name: "description", field: "description", width: 120, minWidth: 120, cssClass: "cell-title", sortable: true }
];
如何获取所有选中/选中的行。 我的方法:
function GetCheckedRows() {
var checkedRows = [];
for (var i = 0; i < grid.getDataLength(); i++) {
if (grid.getDataItem(i).isChecked)
checkedRows.push(grid.getDataItem(i));
}
console.log(checkedRows);
}
调用 GetCheckedRows 永远不会返回第一个选中的行,第二个选中的行来,并且取消选择不会从 checkedRows 中删除。
【问题讨论】: