I am trying to make a Vue app that lists company offices based on regions. I have a main home view, an offices components, and an office item component. I am using v-for in the offices component to loop through the office items and display them. That works to list them all out. However, I need to sort the office items into separate divs based on the value of "Region". There are 5 regions. I cannot figure out how to loop through them based on that single value.
I know how to import components to one another, but I am trying to loop through all of the office items within the offices component. My guess is to do a loop within a loop, but do I need another component that I'm missing?
office item component:
<div class="office" :class="office.Region">
<p>{{office.Name}}</p>
<p>{{office.Address}}</p>
<p>{{office.Country}}</p>
<p>{{office.Region}}</p>
<p>{{office.Email}}</p>
<p>{{office.Phone}}</p>
</div>
offices component:
<div>
<div v-for="office in offices" :key="office.name">
<div class="office-container global" v-if="office.Region === 'Global'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container north" v-if="office.Region === 'North America'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container europe" v-if="office.Region === 'Europe, Middle East and Africa'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container asia" v-if="office.Region === 'Asia Pacific'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container latin" v-if="office.Region === 'Latin America'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
</div>
</div>
a hardcoded array of objects:
offices: [
{
Name: "Corporate Headquarters",
Address: "Suite 500, 698 West 10000 South, South Jordan, Utah 84095",
Country: "USA",
Region: "Global",
Email: "[email protected]",
Phone: "+1-888-253-6201"
},
{
Name: "EMEA Headquarters",
Address: "First Floor Europa House, Harcourt Street Dublin 2, D02 WR20",
Country: "Ireland",
Region: "Europe, Middle East and Africa",
Email: "[email protected]",
Phone: "+ 353 1 411 7100"
},
{
Name: "India",
Address: "Bagmane Tech Park, Unit No. 4A, Level 2 , Bangalore",
Country: "India",
Region: "Asia Pacific",
Email: "[email protected]",
Phone: ""
},
{
Name: "Brazil",
Address: "Borges de Figueiredo, 303 - 4th floor, Bairro Mooca, São Paulo, SP 03110-010",
Country: "Brazil",
Region: "Latin America",
Email: "[email protected]",
Phone: "+55 11 9 8136 0343"
},
{
Name: "United States (Seattle)",
Address: "1011 Western Ave SW #700, Seattle, WA 98104",
Country: "United States",
Region: "North America",
Email: "[email protected]",
Phone: "+1-206-274-4280"
}
]
I want there to be only 5 office-container divs with the list of corresponding offices in each one. however, I get multiple office-container (i.e. two north America divs) and multiple empty divs inside of those
Region?