B
B
beduin012017-01-12 20:36:10
Vue.js
beduin01, 2017-01-12 20:36:10

How to bind checkboxes to an array in Vue.JS?

I need to form an array of clicked elements (checkboxes).

The code is simple:

<div class="imgType">
    <div v-for="img in images_types" v-bind:value="img">
      <div><input type="checkbox" v-model="selected_images_types">{{img}}</div>
    </div>
  </div>


At the moment I have an array output:
[ ] foo
[ ] bar
[ ] baz

The problem is that when you click on any element, the checkbox selects all other elements. And I need it not to select and the selected elements fall into the `selected_images_types` variable, i.e.
selected_images_types = ["foo", "bar"]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
Xorton, 2017-01-12
@beduin01

https://jsfiddle.net/rmjd8zp4/
v-bind:value="img" should be moved to input

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question