mercredi 28 juin 2017

Vuejs + Vuex Get checkbox status (checked)

I would like get the checkbox status from store. I made a Comparison with the checkbox list and "active checkbox" list ( inArray(checkList.value, activeFilters) ), but I can't get the value from this.$store.getters.updateFilters. Here the code:

 <template>
    <li class="dropdown-child">
        <label >
            <input
                type="checkbox"
                :name="checkList.id"
                :value="checkList.name"
                :checked="inArray(checkList.value, activeFilters)"
                @change="updateFilter"
                >
            <span></span>

        </label>
    </li>
</template>


<script>

    export default {
        props: ['checkList'],
        computed: {

            inArray (filterValue, filterChecked) {
                const intComparison = /^[+-]?\d+$/.test(filterValue)
                for (let i = 0, l = filterChecked.length; i < l; i++) {
                    if ((intComparison && parseInt(filterChecked[i], 10) === parseInt(filterValue, 10)) || (filterChecked[i] === filterValue)) {
                        return true
                    }
                }
                return false
            },

            activeFilterList(){
                return this.$store.getters.updateFilters;
            }
        },
        methods: {

            updateFilter (evt) {
                const elm = evt.target || evt.srcElement
                const action = elm.checked === false
                    ? this.removeFilter(elm) //elm.checked
                    : this.addFilter(elm)
                const value = /^[+-]?\d+$/.test(elm.value)
                    ? parseInt(elm.value)
                    : elm.value
            },

            addFilter(elm){
                this.$store.dispatch('addFilter', elm);
            },

            removeFilter(elm){
                this.$store.dispatch('removeFilter', elm);
            }

        }
    }
</script>




Aucun commentaire:

Enregistrer un commentaire