[Vuejs]-Vue, checking pre rendered checkboxes in modal from axios result

0👍

Something along these lines should work…

   @foreach($getResults as $k => $result)
      <tr class="" id="">
        <td>
        <a id="show-modal" @click="showModal = {{$k}}; getDetails('{{$result->group_marketing_copyt_id}}');">{{$result->number}}</a>
        <modal v-if="showModal==={{$k}}" @close="showModal = false">
        <h2 slot="header">{{$result->number}}- {{$result->name}}</h3>
        <div slot="context" >

            <input :checked="direct" type="checkbox" name='direct' data-md-icheck  />
            <input :checked="internal" type="checkbox" name='internal' 
            data-md-icheck  />
            <input :checked="mix" type="checkbox" name='mix' data-md-icheck  />
        </div>

        <div slot="body">
        <textarea style="width:100%; margin: 0 auto;">{{utf8_encode($result->text)}}</textarea>
        </div>

        </td>
    </tr>
    @endforeach


     new Vue({
            el:'#app',
                data: { 
                    showModal: false,
                    mix: false,
                    internal: false
                },
                methods: {
                    getDetails: function(rID){
                        console.log(rID);
                        console.log('nice');

                        let data = {rID:rID};
                        axios.post('/details', data)
                        .then((response) => {

                           response.data.forEach(element => {
                            if(element.result_type === "mix" ) {
                               this.mix = true;
                            } else if (element.result_type === "internal"){
                               this.internal = true;
                            }
                           });

                        })
                        .catch(function (error) {
                            console.log(error);
                        })
                        .finally(function () {
                            console.log('done');
                        });

Leave a comment