【发布时间】:2017-11-17 00:09:39
【问题描述】:
这个问题是从这里发布的:
VueJS Accordion Table - Appears outside of the table
@Bert Evans 提供的答案很好,但是,在我正在开发的系统中,有一些限制使其无法正常工作。
主要的限制是我正在开发一个基于实时的系统,它利用了store,所以当用户编辑某些内容时,会触发一个动作,再次提取所有数据来自 ajax 调用。提供的解决方案使用contentVisible,虽然我可以在调用动作时映射它,主要问题是每当调用动作时,contentVisible 默认设置为false,导致手风琴关闭。
我已尝试创建数据的副本,但这还不够。基本上,我需要一种方法来检测有人单击了特定行,然后在其下方显示手风琴。
有什么建议吗?
console.clear()
var vm = new Vue({
el: '#vue-instance',
data: {
testing: [{
id: 1,
name: "Customer 1",
contentVisible: false
},
{
id: 2,
name: "Customer 1",
contentVisible: false
},
{
id: 3,
name: "Customer 3",
contentVisible: false
},
],
columns: ["id", "name"]
},
mounted() {
console.log(this.testing);
},
methods: {
showRow(data) {
this.contentVisible = !this.contentVisible;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.js"></script>
<div id="vue-instance">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th v-for="column in columns">
{{column}}
</th>
</tr>
</thead>
<tbody>
<template v-for="row in testing">
<tr @click="row.contentVisible = !row.contentVisible">
<td>{{row.id}}</td>
<td>{{row.name}}</td>
</tr>
<tr v-if="row.contentVisible">
<td :colspan="columns.length" >
<div class="accordian-body">
afasfafs
</div>
</td>
</tr>
</template>
</tbody>
</table>
</div>
【问题讨论】:
-
如果所有数据都被替换了,你怎么知道应该打开哪些?
-
@Roy J - 感谢您的回复。理想情况下,当数据被替换时,不需要知道哪些是打开的。只是手风琴需要知道哪一行是打开的。 IE。如果数据被替换,那么它不应该真正更新手风琴状态,因为行 (100) 可以扩展手风琴但行 (1) 已更改。因此第 1 行不应该受到影响。如果这有意义?
标签: jquery vue.js vue-component