weixin_43082585 2019-07-18 13:21 采纳率: 0%
浏览 6717

Layui框架的table的选中行功能,获取选中行数据为空!!有没有大佬帮忙看看啊,查了各种资料都不行!!!

 <table class="layui-hide" id="user-index"  lay-filter="user-index"></table>
<script>
        layui.use(['layer', 'table'], function () {
            var $ = layui.$
                , layer = layui.layer
                , form = layui.form
                , table = layui.table; //独立版的layer无需执行这一句
            var tableId = 'user-index';
            var tableToolbar = 'user-index-toolbar';
            var tableSearchForm = 'user-index-search';
            var minWidth = 768;

            // 表格渲染
            table.render({
                elem: '#' + tableId
                , toolbar: '#' + tableToolbar
                , defaultToolbar: ['filter'] // ['filter', 'print', 'exports']
                , url: '/User/list'
                ,where:{'username':'','realname':'','tel':'','city':'','isdelete':0}
                , method: 'get'
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
                , cols: [[
                    {type: 'checkbox', id:'cb',fixed: 'left'}
                    , {field: 'id', width: 80, title: 'ID', sort: true}
                    , {field: 'username', width: 212, title: '用户名', sort: true}
                    , {field: 'realname', width: 100, title: '姓名'}
                    , {field: 'sex', width: 105, title: '性别'}
                    , {field: 'tel', width: 180, title: '手机号'}
                    , {field: 'city', width: 120, title: '城市', sort: true}
                    , {field: 'role', width: 100, title: '角色ID', sort: true}
                    , {
                        title: '状态', width: 150,
                        templet: function (res) {
                            if (res.status == '1') {
                                return '已激活(使用中)';
                            } else {
                                return '<span style="color: #F581B1;">冻结(过期请续费)</span>';
                            }
                        }
                    }
                ]]
                , page: true
                ,limit:7
                , height: 'full-60' // 100
            });

头工具栏的监听

 table.on('toolbar(' + tableId + ')', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id) 
            , data = checkStatus.data;
               console.log(data) //获取选中行的数据

结果我选中一条或者是多条数据之后都获取不到数据,table的id我也检查过了没问题。
前端控制台输出是这样的:

Object
data: Array(0)
length: 0
__proto__: Array(0)
isAll: false
__proto__: Object

但是我又试了全选,神奇的发现全选能选择,有没有大佬能帮忙解释下这是什么问题啊,怎么才能解决

  • 写回答

9条回答

  • weixin_43082585 2019-07-18 13:23
    关注

    全选数据都是有的,但单选或者选择部分就不行,输出都都是0

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置