I want to delete the nested array 'Men' in the items. And also I want to add the new data inside the nested array 'Human' using the function addingData and removingData. I have tried slice and pop function but that didn't work on child
This is html code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale">
<title>Graph</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in items">
{{item.root}} -
<button v-on:click="addingData(item.id)"> + </button>
<button v-on:click="removingData(index)"> - </button>
<ul>
<li v-for="(child, child_index) in item.childs">
{{child.root}} - <button v-on:click="addingData(child_index)"> + </button>
<button v-on:click="removingData(child_index)"> - </button>
<ul>
<li v-for="(childLevel2, childLevel2_index) in child.childs">
{{childLevel2.root}} -
<button v-on:click="addingData(child_index)"> + </button>
<button v-on:click="removingData(childLevel2_index)"> - </button>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="main.js"></script>
</body>
</html>
This is javascript code
var app = new Vue({
el:'#app',
data:{
items: [
{
id: 1, root : 'Animal', childs:[
{id: 3, root: 'Human', childs:[
{id: 4, root: 'Men' ,childs: null},
{id: 5, root: 'women', childs: null}
]},
{id: 6, root: 'bunny', childs: null},
{id: 7, root: 'fish', childs: null}
]
},
{id: 2, root : 'Vehicle', childs: [
{id: 8, root: 'Car'},
{id: 9, root: 'Bike'}
]}
]
},
methods: {
addingData: function(index){
this.items.push({root : 'House'})
console.log(index)
},
removingData: function(index){
console.log(index);
//this.items.splice(index, 1);
Vue.delete(this.items, index);
}
}
})
If someone could take a look I would really appreciate it!