lundi 27 novembre 2017

Select All checkboxes in vue.js

Here is my fiddle : DEMO

1) On choice of all checkboxes, "Select All" should get checked.

2) On check of "Select All", all the checkboxes should get checked at once.

3) After checking "Select All", if one or more checkbox is unchecked, select all gets unchecked.

How can this be done in vuejs? The closest example I found was http://ift.tt/2iWNp0T but could not get it to work in my code.

computed: {
    selectAll: {
        get: function () {
            return this.users ? this.selected.length == this.users.length : false;
        },
        set: function (value) {
            var selected = [];

            if (value) {
                this.users.forEach(function (user) {
                    selected.push(user.id);
                });
            }

            this.selected = selected;
        }
    }
}

Any help would be much appreciated. Thank you :)




Aucun commentaire:

Enregistrer un commentaire