flexigrid 编程实现选中checkbox
发布时间:2020-12-15 04:43:33 所属栏目:百科 来源:网络整理
导读:原理是 1.遍历flexigrid产生的table对象, 2.根据一定的规则(取决于业务需求)查找到某行的某列值就是要匹配的值,然后返回input对象 3.对该input对象调用attr('chceked','checked')方法,设置为勾选状态。 例子代码: //return input jquery object if the
原理是 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 returned findPower : 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,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); } } }, updateCheckboxStatus函数接受两个参数,一个是flexigrid对象grid,一个是数组powers。 首先遍历powers数组,将当中的每个值拿到grid中查找。 查找由findPower函数实现。使用jquery对象逐行查找,找到后,返回input对象。 一旦找到,则调用selectRow函数设置勾选状态。 因此,基本上我的用法是把flexigrid看成一个前端table渲染器,只有后续的高级操作,直接对dom操作吧。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |