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