记录Bootstrap Table与JQ的自己踩的坑

记录Bootstrap Table与JQ的自己踩的坑

因为本人需要做一个功能模块,期间要用到bootstrap table,具体流程是后台传输数据到前端,根据数据某个状态来判定table上的复选框是否打上勾。

<table id="webViewListTable" data-total-rows="${webViewListTotal}" data-data-type="html" data-page-size="50" data-pagination="true"
           data-page-list="[50, 100, 200]"
           data-toggle="table" data-id="getWebViewDetail" data-side-pagination="server">
           //下面就是你要显示的行和列   数据的话使用的for each 循环来遍历
           <thead>
        <tr>
            <th data-checkbox="true" ></th>
            <th data-field="id" data-visible="false"></th>
            <th data-field="isVisible" data-visible="false"></th>
            <th data-field="fieldCaption" data-sortable="true">选择需要显示的表头字段</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${webViewList}" var="webView">
            <tr class ="verify" >
                <td></td>
                <td>${webView.id}</td>
                <td>${webView.isVisible}</td>
                <td>${webView.fieldCaption}</td>
            </tr>
        </c:forEach>
        </tbody>
</table>

然后就是JS了,因为当时使用bootstrap table的方法来获取表格所有的数据

var data= $('#table').bootstrapTable('getData',true);

但是获取的数据好像是当前的window.location的信息返回出来了,我用页面的点击方法在来重新获取table里面的数据进行对比。
对比
发现是对不上。因为使用的是JQ的 ready(文档就绪事件),可能是文档已经加载完毕了,bootstrap table还没有加载完成,所以就取不出来数据。
使用延迟策略,在ready时间里面使用setTimeout,就可以取出完整的table数据
bootstrap rable使用详情可以点击Bootstrap Table

 $(function () {
        setTimeout(function () {
          },10)
	var data= $('#table').bootstrapTable('getData',true);
	//根据条件选择某一行  例:根据id 1 和2 来选中这一行
	$('#table').bootstrapTable('checkBy', {field: 'id', values:[1,2]});
    })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值