flexigrid 编程实现选中checkbox
原理是
1.遍历flexigrid产生的table对象,
2.根据一定的规则(取决于业务需求)查找到某行的某列值就是要匹配的值,然后返回input对象
3.对该input对象调用attr('chceked','checked')方法,设置为勾选状态。
例子代码:
//return input jquery object if the power.name is found in one row//otherwise null will be returnedfindPower : function (powerName, grid) {var rows, length, i, input, row;rows = grid.children('tbody').eq(0).children('tr');length = rows.length;for (i = 0; i < length; (i += 1)) {row = rows.eq(i);input = row.children('td').eq(0).children('div').eq(0).children('input').eq(0);if (input.val() === powerName) {return input;}}return null;},selectRow : function (input) {input.attr("checked", "checked");},updateCheckboxStatus : function (grid, powers) {var length, i, input;length = powers.length;if (length === 0) {return;}for (i = 0; i < length; (i += 1)) {input = accounts.findPower(powers[i], grid);if (input !== null) {accounts.selectRow(input);}}},首先遍历powers数组,将当中的每个值拿到grid中查找。
查找由findPower函数实现。使用jquery对象逐行查找,找到后,返回input对象。
一旦找到,则调用selectRow函数设置勾选状态。
因此,基本上我的用法是把flexigrid看成一个前端table渲染器,只有后续的高级操作,直接对dom操作吧。