I am doing a function to delete more then one record based on the checkboxes selected but as I receive the ID (not the full object) I am facing problems to remove it from the array.
Somebody can help me?
JS:
new Vue({
el: 'body',
data: {
record: {},
selected: [],
list: [
{ name: 'Google', id: 1, cat: 'Category 1' },
{ name: 'Facebook', id: 2, cat: 'Category 2' },
],
},
methods: {
deleteSelected: function () {
for (var r in this.selected) {
this.list = this.list.filter(function(val, i) {
return val.id !== this.selected[r];
});
}
}
}
});
HTML:
<body>
<div class="container">
<div class="row p-10">
<div class="col-md-6 m_md_bottom_15">
<span class="btn btn-danger" data-toggle="tooltip" data-original-title="Delete" @click="deleteSelected()">Remove selected</i></span>
</div>
</div>
<hr>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="r in list">
<td><input type="checkbox" v-model="selected" value="{{ r.id }}"></td>
<td class="text-center" style="width:90px"> {{ r.id }} </td>
<td> {{ r.name }} </td>
<td class="text-center" style="width:90px">
<span class="btn btn-warning btn-xs" @click="edit(r)"><i class="fa-fw fa fa-pencil"></i></span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="container">
<pre>{{ $data | json }}</pre>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.20/vue.min.js"></script>
</body>