我正在使用Bootstrap Vue中的Table,并且试图在单击一行时显示行详细信息。
我使用doc所说的row-clicked
事件,但是使用toggleDetails
方法找不到任何行详细信息。
因此,我什至不知道如何打开它以及toggleDetails
的来源。
有一种方法可以通过row.clicked
事件打开此详细信息行?
还是应该使用其他方法来做到这一点?
您有一些线索吗?
编辑
有一些代码可以进一步说明我的问题,我的表包含明细行。
<b-table
v-if="items"
:items="items"
:fields="fields"
show-empty
striped
hover
responsive
empty-text="There is no messages to show"
class="col-sm-12 col-md-10"
@row-clicked="test"
>
<template
slot="message"
slot-scope="row"
>
{{ row.item.message }}
</template>
<template
slot="row-details"
slot-scope="row"
>
<code>{{ row.item.message }}</code>
</template>
</b-table>
您可以看到我在表上使用的row.clicked
事件,然后可以看到我试图打开行详细信息的方法。这是一些console.log的简单方法。
methods: {
test(item, index, event) {
console.log(item, index, event);
},
},
答案 0 :(得分:3)
所有您需要做的就是在“基本”行中的某个位置(可能在名为 actions 的行单元中)放置一个按钮,该按钮为此特定行调用toggleDetails
函数。
此按钮和详细信息行的代码应如下所示:
<template slot="actions" slot-scope="row">
<!-- We use @click.stop here to prevent a 'row-clicked' event from also happening -->
<b-button size="sm" @click.stop="row.toggleDetails">
{{ row.detailsShowing ? 'Hide' : 'Show' }} Details
</b-button>
</template>
<template slot="row-details" slot-scope="row">
<!-- Your row details' content here -->
</template>
您可以在documentation
中找到更多示例和说明。如果要通过单击行中的任意位置来显示行详细信息,首先应为每个项目对象添加一个_showDetails
变量:
items: [
{ foo: true, bar: 40, _showDetails: false },
...
{ foo: true, bar: 100, _showDetails: false }
]
然后,您只需要为行单击事件添加适当的功能:
<b-table @row-clicked="onRowClicked" ...></b-table>
在您的组件方法中:
methods: {
onRowClicked (item, index, event) {
item._showDetails = !item._showDetails;
}
}