2

I have made a codepen demonstrating a problem I'm having with a checkbox not working. On changes, the value of clipsData does not get updated.

https://codepen.io/bozlurrahman/pen/BeZVzR?editors=1010


<div id="video-clips-wrap">
    <div>{{clipsData}}</div>

    <li v-for="(clip, index) in clips" v-bind:key="index">

        <div class="vl-subsource-container">

            <input type="checkbox" value="issubsource" v-model="clip.subsourcesettings" v-on:change="viewSubSource(index)"><label>Not Update on change: {{clip.issubsource}}</label>

            <div v-if="clip.subsourcesettings.length">
                <label>Dynamic Contents</label>
            </div>

        </div>
        <div class="meditations-options">
            <label>Meditations: </label>
            <input type="checkbox" value="motivation" v-model="clip.meditations"><label>1. Motivation</label>
            <input type="checkbox" value="gratitude" v-model="clip.meditations"><label>2. Gratitude</label>

        </div>

    </li>
</div>

var video_clip_data_var = "[{\"meditations\":[\"motivation\",\"gratitude\"]}]";
var VideoClip = new Vue({
    el: '#video-clips-wrap',
    data: {
        clips: [],
        loading: false,
    },
    created: function () {

        this.clips = JSON.parse(video_clip_data_var);

        for (var i = 0; i < this.clips.length; i++) {

            // if( typeof this.clips[i].meditations == "string" )
            //  this.clips[i].meditations = this.clips[i].meditations.split(',');

            this.clips[i].subsourcesettings = "issubsource".split(',');
            this.clips[i].subsources = [];
        }

    },
    methods: {
        viewSubSource: function (index) {
            console.log(`this.clips[`+index+`].subsourcesettings`,this.clips[index].subsourcesettings);
            console.log(`this.clips`,this.clips);
            // this.clipsData = JSON.stringify(this.clips);
        },
    },
    computed: {
        clipsData: function () {
            return JSON.stringify(this.clips);
        },
    }
});

Is there any one who can help me to fix this problem? When clicking on the check box, the hidden content should show directly. Thanks.

1
  • There is no {{clip.issubsource}} inside 'clip' object instead issubsource is a 'subsourcesettings' Array's item. Is that may a problem? Commented May 18, 2019 at 7:23

1 Answer 1

2

Replace that

this.clips[i].subsourcesettings = "issubsource".split(',');
this.clips[i].subsources = [];

to

Vue.set(this.clips[i], 'subsourcesettings', "issubsource".split(','))
Vue.set(this.clips[i], 'subsources', [])

Here you can find more details about your problem.

Sign up to request clarification or add additional context in comments.

Comments

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.