layui table checkbox默认选中

var ids = [];
    var textid;
    var warehouse_id;
 function getRole(id) {
        table.render({
            elem: '.role-table'
           , url: '/api/warehouse/warehouseModule'
            , where: { warehouseId:id}
           , cols: [[
              { type: 'checkbox', field: 'LAY_CHECKED', title: '序号', width: '15%' }
               
                , { field: 'role_name', width: '70%', title: '岗位名称', align: 'center', rowspan: '1' }
           ]]
          
           , done: function (res, curr, count) {
               textid = res.data;
               warehouse_id=id;
               for (var i = 0; i < res.data.length; i++) {
                   if (res.data[i].LAY_CHECKED == "true")
                   {
                       ids.push(res.data[i].id);
                   }
               }
               form.render();
           }
           , headers: { Authorization: 'token ' + token }
           , id: 'list'
        });
        form.on('checkbox', function (obj) {
        });
        table.on('checkbox(filter)', function (obj) {
            var data = obj.data;
            var laybox = $("input[name='layTableCheckbox']");
            if (obj.checked) {
                if (obj.type == 'one') {
                    ids.push(data.id);
                } else {
                    for (var i = 0; i < textid.length; i++) {
                        ids.push(textid[i].id);
                    }
                }
            } else {
                if (obj.type == 'one') {
                    for (var i = 0; i < ids.length; i++) {
                        if (ids[i] == data.id) {
                            ids.splice(i, 1);
                        }
                    }
                } else {
                    for (var i = 0; i < ids.length; i++) {
                        for (var j = 0; j < textid.length; j++) {
                            if (ids[i] == textid[j].id) {
                                ids.splice(i, 1);
                            }
                        }
                    }
                }
            }
        });
    }
   

后台LAY_CHECKED给定true或false 验证CheckBox是否选中

posted @ 2020-03-25 13:32  艺洁  阅读(12880)  评论(1编辑  收藏  举报