vue.js - 可以通过复选框选择 bootstrap-vue 表行选择吗
问题描述
我目前有一个引导 vue 表,其中左列都是复选框。我已将表格行设置为可选择的,这工作正常。我希望能够通过复选框选择行,而不是点击实际的 .
我还想知道是否可以通过左上角的复选框选择所有行。
看看我的 jsfiddle 看看我现在有什么。
- 可通过复选框为每行选择行
- 可通过左上角复选框选择所有行
https://jsfiddle.net/itsjess/mLztuf6o/2/
<b-table id="my-table" class="mb-20" :borderless="true"
:items="merchants" :fields="fields" selectable @row-
selected="rowSelected" selectedVariant="success" :per-
page="perPage" :current-page="currentPage" small responsive>
<template slot="HEAD_index" slot-scope="data">
<b-form-checkbox></b-form-checkbox>
</template>
<template slot="index" slot-scope="data">
<b-form-checkbox :id="'checkbox' + data.index" v-model="data.item.index" checked="checked">
</b-form-checkbox>
</template>
<template slot="outlet" slot-scope="data">
{{ data.item.name }}
</template>
<template slot="orderacc" slot-scope="data">
on
</template>
<template slot="taskcomp" slot-scope="data">
40%
</template>
</b-table>
解决方案
我没有看到任何支持通过引导表中的复选框选择行,因此您可能必须自己处理这种情况:
删除selectable
和@row-selected
绑定并将所选项目添加到您自己的数组中。我从你的 jsfiddle 准备了一些实现:https ://jsfiddle.net/maxsinev/unp7jzwo/
PS 如果您将拥有包含动态项目的表格,您将通过某些 API 接收这些动态项目,则有必要将其存储uuid
为复选框值而不是对象引用(如在我的 jsfiddle 中)。
推荐阅读
- javascript - 最大化事件的使用
- flutter - 参数类型'Map
' 不能分配给参数类型 'Map ' - php - 如何实现else显示简单文本回显php
- mongodb - 将 mongodb-1.2.2 与 Rocket-0.5.0-rc.1 一起使用会导致异步运行时不兼容
- angular10 - 单击添加按钮后,如何将我的文本区域的值设为空白,您能帮帮我吗?
- python - 在 django 中在 POST 请求和 GET 之间传输数据时出现问题
- html - 打字机对标题标签的影响
- javascript - 滚动到顶部不适用于 jupyter 笔记本
- r - 时间序列数据的for循环
- amazon-web-services - EKS Application Load Balancer AccessDenied 无权执行