EasyUI 1.3之前DataGrid中动态选中、获取Checkbox

这几天做项目,由于项目中用到的EasyUI版本过低,不能使用自带操作DataGrid中CheckBox的方法。

所以自己写了一个临时方案:

根据ID集合选中所属行的CheckBox:

 1 data={1,2,3,4,5,6};//需要选中项的ID
 2 var funId = data.split(',');
 3                     var iden = []; //记录行标记(ProjectFunctionId等于指定值的行)
 4                     var x = 0;  //自增行标记
 5                     for (var i = 0; i < funId.length; i++) {//遍历功能ID
 6                         $("table").find("tr").each(function () {//遍历TR
 7                             $(this).find("td").each(function () {//遍历TD
 8                                 if ($(this).attr("field") == "ProjectFunctionId") {//查找field属性等于ProjectFunctionId的集合
 9                                     $(this).find("div").each(function () {//在集合中查找DIV
10                                         if ($(this).text() == funId[i]) {//div text属性值等于功能ID
11                                             iden.push(x);   //记录行标记
12                                             return true;
13                                         }
14                                     });
15                                 }
16                             });
17                             x++;        //行标记自增
18                         });
19                     }
20                     x = 0;
21                     for (var i = 0; i < funId.length; i++) {
22                         $("table").find("tr").each(function () {
23                             $(this).find("td").each(function () {
24                                 if ($(this).attr("field") == "check") {
25                                     if (iden[0] == x) {
26                                         $(this).find("div:first").each(function () {
27                                             $(this).find(":checkbox").each(function () {
28                                                 $(this).attr("checked", true); //为checkbox添加checked属性
29                                                 iden.splice(0, 1); //移除下标为0的行标记
30                                                 return true;
31                                             });
32                                         });
33                                     }
34                                 }
35                             });
36                             x++;
37                         });
38                     }

获取CheckBox选中行的某列值:

 1  //获取所有选中checkbox的value
 2             var functionIds = "";
 3             var iden = [];
 4             var x = 0;
 5             $("table").find("tr").each(function () {
 6                 $(this).find("td").each(function () {
 7                     if ($(this).attr("field") == "check") {
 8                         $(this).find("div:first").each(function () {
 9                             $(this).find(":checkbox").each(function () {
10                                 if ($(this).attr("checked") == true) {
11                                     iden.push(x);
12                                     return true;
13                                 }
14                             });
15                         });
16                     }
17                 });
18                 x++;
19             });
20             x = 0;
21             $("table").find("tr").each(function () {
22                 $(this).find("td").each(function () {
23                     if ($(this).attr("field") == "ProjectFunctionId") {
24                         if (iden[0] == x) {
25                             $(this).find("div:first").each(function () {
26                                 functionIds += $(this).text() + ",";
27                                 iden.splice(0, 1);
28                                 return true;
29                             });
30                         }
31                     }
32                 });
33                 x++;
34             });

希望对大家有所帮助,不过这只是临时解决方案,有更好的方案以后会放上来。

转载于:https://www.cnblogs.com/FelixLiu/p/3497610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值