I have some menus in table. There are some sub-menus under the menus. I want to display them in a table. I am trying this--
new Vue({
el: '#app',
data: function() {
return {
menus: [
{ id: 1, menuName: "Tech 1" },
{ id: 2, menuName: "Tech 2" },
{ id: 3, menuName: "Tech 3" }],
selectedMenu: [],
submenus: [
{ id: 1, menuId: 1, subMenuName:"architecture" },
{ id: 2, menuId: 1, subMenuName:"Electrical" },
{ id: 3, menuId: 1, subMenuName:"Electrical" },
{ id: 4, menuId: 2, subMenuName:"IEM" },
{ id: 5, menuId: 3, subMenuName:"CIVIL"}],
}
},
computed: {
filteredProduct: function () {
const app = this,
menu = app.selectedMenu;
if (menu.includes("0")) {
return app.submenus;
} else {
return app.submenus.filter((p) => menu.includes(p.menuId));
}
},
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"
><div id="app">
<table class="table">
<thead>
<tr>
<th>Menu</th>
<label><input type="checkbox" v-model="selectedMenu" value="0" />
All</label</th>
<th>Submenu</th>
</tr>
</thead>
<tbody>
<tr v-for="menu in menus" :key="menu.id">
<td>
<label>
<input
type="checkbox"
:value="menu.id"
v-model = "selectedMenu"
/>{{ menu.menuName }}
</label
>
</td>
<td>
<ul>
<li
v-for="submenu in filteredProduct"
:key="submenu.id">
<input type="checkbox" :value="submenu.id"/>
<label>{{ submenu.subMenuName }} </label>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
My problem is, When I click on any menu, The submenus are showing on other columns too.
When I click on any menu, the submenus associated with that menu should display in that particular row. How do I do this?