jef*_*des 3 javascript vue.js vue-component vuejs2 bootstrap-vue
我有一张装满数据的表格。我selected对要绑定到 b 表中的复选框的数据有一个属性。我似乎无法弄清楚如何做到这一点。
我的数据:
data: () => ({
tableData: [
{
title: "title01",
desc: "desc01",
selected: false
},
{
title: "title02",
desc: "desc02",
selected: false
},
],
tableColumns: [
{ key: "selected", label: "", sortable: false }
{ key: "title", label: "Title", sortable: false },
{ key: "desc", label: "Description", sortable: false }
})
Run Code Online (Sandbox Code Playgroud)
html:
<b-table id="myTabel"
hover
striped
:items="tableData"
:fields="tableColumns">
<template slot="selected" slot-scope="row">
<b-form-group>
<input type="checkbox" v-model="How_To_Bind_To_Object_Prop?">
</b-form-group>
</template>
</b-table>
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我无法v-model设置实际绑定到表数据。
v-model="tableData.selected"将所有复选框绑定到所有数据对象。所以,如果你检查一个,你检查所有,反之亦然。我只是不知道如何将它绑定到该行的数据。
我可以通过使用更传统的 HTML 并使用 Vuev-for循环遍历tableData以绑定每个表格行来做到这一点。但是,我们正在尝试将大部分(如果不是全部)表单转移到使用 bootstrap-vue。
所以,这很好用:
<table>
<thead>
<tr>
<th :key="key" v-for="(tableColumn, key) in tableColumns">
{{ tableColumn.label }}
</th>
</tr>
</thead>
<tbody>
<tr :key="key" v-for="(tableRow, key) in tableData">
<td>
<input type="checkbox"
v-model="tableRow.selected">
</td>
<td>
{{ tableRow.title }}
</td>
<td>
{{ tableRow.desc }}
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
您可以在作用域插槽内按如下方式访问行项目并将嵌套复选框绑定到selected属性:
<template v-slot:cell(selected)="row">
<b-form-group>
<input type="checkbox" v-model="row.item.selected" />
</b-form-group>
</template>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅表格 - 自定义呈现文档。
| 归档时间: |
|
| 查看次数: |
12492 次 |
| 最近记录: |