I'm trying to select all input fields when I click the Select all names button but that's not working?
I've made a example:
new Vue({
el: '#app',
data: {
names: [
{ "name": "one" },
{ "name": "two" },
{ "name": "three" }
]
},
created() {
this.names.filter(name => name.checked = false);
},
methods: {
selectAll() {
this.names.filter(name => name.checked = true);
}
}
})
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<div id="app">
<table>
<tr>
<th>Names</th>
</tr>
<tr v-for="name in names">
<td>
<input type="checkbox" v-model="name.checked">{{name.name}} </td>
</tr>
</table>
<button @click="selectAll()">
Select all names
</a>
</div>
What am I doing wrong here?