samynmhd
samynmhd

Reputation: 17

How to get all the array values from vue response

How do i access the full course array enter image description here

the code below gives me the first course array.

<div class="form-group"  v-show="school === 'SOSE'">
      <label for="course">Course</label>
      <select class="form-control" name="course" v-model="course">
        <option v-for="(result, index) in response" :value="result.course[0].initial">{{result.course[0].name}}</option>
      </select>
    </div>

if i use the index, course becomes undefined. How do i get values in both arrays.

Code for fetching data.

created() {
    axios.get(`https://${location.host}/admin/getSchool`)
      .then(resp => {
        this.response = resp.data;
        console.log(this.response);
      })
      .catch(err => {
        this.errors.push(err);
      })
  },

Upvotes: 0

Views: 578

Answers (2)

Crackers
Crackers

Reputation: 1125

You will have to use two v-for here I used the template tag for it.

  <select class="form-control" name="course" v-model="course">
    <template v-for="result in response">
      <option v-for="course in result.course" :value="course.initial">{{course.name}}</option>
    </template>
  </select>

Upvotes: 1

Chanh
Chanh

Reputation: 443

nodejs

try

result.forEach(function(item){
    console.log('initial: ' + item.initial);
    console.log('name: ' + item.name);
});

Hope it will be useful

Upvotes: 0

Related Questions