Ticker

6/recent/ticker-posts

how to select vuejs check all uncheck all checkboxes

<div class="container">
<div id="app">
<h4>Names</h4>
<div>
<table class="table">
<tr>
<th><input type="checkbox" v-model="checkAll"></th>
<th align="center">ID</th>
<th align="center">Names</th>
</tr>
<tr v-for="lang in langs">
<td>
<input type="checkbox" v-model="checked" :value="lang.id" number>
</td>
<td> {{ lang.id }}</td>
<td> {{ lang.name }}</td>
</tr>
</table>
</div>
</div>
</div>
view raw index.html hosted with ❤ by GitHub
new Vue({
data: {
langs: [
{ "id": "1", "name": "Edward"},
{ "id": "2", "name": "Lance"},
{ "id": "3", "name": "Arellano"},
{ "id": "4", "name": "Lorilla"},
],
checked: []
},
computed: {
checkAll: {
get: function () {
return this.langs ? this.checked.length == this.langs.length : false;
},
set: function (value) {
var checked = [];
if (value) {
this.langs.forEach(function (lang) {
checked.push(lang.id);
});
}
this.checked = checked;
}
}
}
}).$mount('#app');
view raw script.js hosted with ❤ by GitHub
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17-beta.0/vue.js"></script>
view raw scripts hosted with ❤ by GitHub
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
view raw styles hosted with ❤ by GitHub

Post a Comment

0 Comments