引导表版本:1.16.0
目的:我想达到全选和多选的效果。
编码:
<table class="table table-bordered" id="order-table">
<thead>
<tr>
<th><input type="checkbox" id="btSelectAll" name="btSelectAll" /></th>
<th>name1</th>
<th>name2</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="btSelectItem" data-index="586"/></td>
<td>val1</td>
<td>val2</td>
</tr>
<tr>
<td><input type="checkbox" name="btSelectItem" data-index="586"/></td>
<td>val1</td>
<td>val2</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(function() {
$table = $('#order-table').bootstrapTable({
search: false,
showColumns: false,
multipleSelectRow: true
});
});
</script>
然后单击复选框,这将触发错误
问题:控制台中出现错误
bootstrap-table.min.js:10 Uncaught TypeError: Cannot set property 'undefined' of undefined
at e.value (bootstrap-table.min.js:10)
at HTMLInputElement.<anonymous> (bootstrap-table.min.js:10)
at HTMLInputElement.dispatch (jquery.min.js:2)
at HTMLInputElement.v.handle (jquery.min.js:2)
value @ bootstrap-table.min.js:10
(anonymous) @ bootstrap-table.min.js:10
dispatch @ jquery.min.js:2
v.handle @ jquery.min.js:2
有人能告诉我为什么会发生这种情况,以及如何解决它吗?或者给予我一个正确的例子?
2条答案
按热度按时间x7rlezfr1#
The issue is with your attribute
data-index
You should not use
data-index
randomly as on checkbok check/uncheckbootstrap-table
gets row of that particular indexSee this fiddle, this fiddle won't give error
Also if you want to use chcekbox in your
td
then you should usedata-checkbox
attribute as shown in this link https://examples.bootstrap-table.com/#column-options/checkbox.html#view-sourceFiddle using
data-checkbox
attribute https://jsfiddle.net/jdvLbwc3/3/sauutmhj2#
在我的例子中,jquery.min.js是在bootstrap-table.min.js之后加载的。在切换顺序之后,错误得到了解决。