0

I am using List Rendering in VueJS to print a list of events from my data. However, for each event there will be a list of sponsors which I would also like to display. I do not see anything in the Vue Documentation which gives an example of this https://v2.vuejs.org/v2/guide/list.html I have tried using the code below but I can't find a solution.

<div id="app">
  <ul>
      <li v-for="event in events" v-bind:key="events.id">
          <p>{{event.eventName}}</p>
          <ul>
            <li v-repeat="eventSponsors">
              {{event.eventSponsors}}
            </li>
          </ul>
      </li>
  </ul>
</div>

var app = new Vue({
  el: '#app',
  data: {
    events: [
      {
        eventName: 'The Open',
        eventSponsors: ['Honda' , 'IBM']
      },
      { 
        eventName: 'Big Cup',
        eventSponsors: ['Nike' , 'Ben & Jerrys']
      }
    ]
  }
})

1 Answer 1

3

Try this. You can create another v-for inside each event

<div id="app">
  <ul>
      <li v-for="(event,index) in events" :key="index">
          <p>{{event.eventName}}</p>
          <ul>
            <li v-for="(sponsor,index) in event.eventSponsors" :key="index">
              {{sponsor}}
            </li>
          </ul>
      </li>
  </ul>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

Your answer works perfectly, so thank you very much. Now I need to try and understand why/how it works. Thanks
great, glad to help, please mark my answer as answer so that it may help other people when encounter the same problem

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.