layui下的table获取选中行数据

静态html:

<table lay-filter="goods-table" id="goods-table" class="table-list my-table-list" cellspacing="0"  cellpadding="0"   style="display: none;">
                <thead>
                    <tr>
                        <th lay-data="{type:'checkbox'}"></th>
                        <th lay-data="{field:'a'}">ID111</th>
                        <th lay-data="{field:'b'}">商品图</th>
                        <th lay-data="{field:'c'}">商品标题</th>
                        <th lay-data="{field:'d'}">商品价格</th>
                        <th lay-data="{field:'e'}">商品品牌</th>
                        <th lay-data="{field:'g'}">产品系列</th>
                        <th lay-data="{field:'h'}">所属供应商</th>
                    </tr>
                </thead>
                <tbody>
                        <tr>
                            <td></td>
                            <td>ID111111</td>
                            <td><img src="http://localhost:9020/images/addImg.png" class="shopImg"/></td>
                            <td>商品标题1</td>
                            <td>¥100</td>
                            <td>商品品牌1</td>
                            <td>产品系列1</td>
                            <td>所属供应商1</td>
                    </tr>
                    <tr>
                    <td></td>
                            <td>ID2222</td>
                            <td><img src="http://localhost:9020/images/addImg.png" class="shopImg"/></td>
                            <td>商品标题2</td>
                            <td>¥200</td>
                            <td>商品品牌2</td>
                            <td>产品系列2</td>
                            <td>所属供应商2</td>
                    </tr>  
                    </tbody>
                </table>        
<div id="page" data-count="10" data-limit="10" data-page="1"></div>

js部分:

获取全部选中的数据:

var selectData =layui.table.checkStatus('goods-table').data;//goods-table是table的id
console.log(selectData);

监听每次选中:

layui.use(['table'], function(){
        var table = layui.table;
        table.on('checkbox(goods-table)', function(obj){
       console.log(obj.checked); //当前是否选中状态
       console.log(obj.data); //选中行的相关数据
       console.log(obj.type); //如果触发的是全选,则为:all,如果触发的是单选,则为:one
       console.log(table.checkStatus('goods-table').data); // 获取表格中选中行的数据
})

猜你喜欢

转载自blog.csdn.net/u012011360/article/details/107044763
今日推荐