0

I'm trying to bind data with model in the vue but I've got an problem if I try to bind data in nested loops.

This is example how I try do it. In result I expect to see all checkboxes are selected, but its don't work and I don't get why?

example https://jsfiddle.net/zmum6cnw/

<div id="element">

<div v-for="filter in filters">
    {{filter.name}}
    <div v-for="option in filter.options">
        <input type="checkbox" v-model="option.status">
        {{option.name}}
    </div>
</div> 
<pre>
    {{filters | json}}
</pre>

var obj = new Vue({
    el: '#element',
    data: {         
        filters: [
        {
            name: '#1',
            options: [
                {
                    checked: true,
                    name: 'A'
                },
                {
                    checked: true,
                    name: 'B'
                },
                {
                    checked: true,
                    name: 'C'
                }
            ]
        },
        {
            name: '#2',
            options: [
                {
                    checked: true,
                    name: 'A'
                },
                {
                    checked: true,
                    name: 'B'
                },
                {
                    checked: true,
                    name: 'C'
                }
            ]
        }
    ]}
    }
})

1 Answer 1

1

Change your input tag as:

<input type="checkbox" v-model="option.status" checked = option.checked>
Sign up to request clarification or add additional context in comments.

1 Comment

I should change to "<input type="checkbox" v-model="option.checked">"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.