[Vuejs]-Why vuejs array shows empty even if it not?

0👍

You declare checked_company as an array, but you treat it as an object checked_company[result.key]

If you want to save all checked company key in an array, then your checkbox code should be

<input type="checkbox" :value="result.key" v-model="checked_company">

Demo: https://jsfiddle.net/ittus/9jya1gas/

0👍

I see you seem missing several div tags

<script src="https://unpkg.com/vue/dist/vue.js"></script>

<div id="app">



    <div id="sidebar-wrapper">
          <button class="collapsible" @click="collapse1=!collapse1">Top Companies</button>
          <div v-if="collapse1" class="content" v-bind:style="{'display': 'block'}">
              <div class="list-group" v-for = "(result,index) in topCompanies" :key="result.id">
              <label class="container check-an" :id="index" @change = "getResultsByCompany(result.key)">{{ result.key}}({{result.doc_count }})
                  <input type="checkbox" v-model="checked_company[result.key]">
                  <span class="checkmark"></span>
              </label>
            </div>

</div>
</div>
</div>

It make vuejs don’t know el scope

-1👍

I’m not really sure this will be the issue but have you checked that ‘this’ refers to the correct object? Potentially you could assign a variable to new Vue and reference the object globally. Hope it helps.

Leave a comment