I am able to list the band members by instrument name, but want to display the instrument name only once, instead of showing the instrument name for each person in the bassoon group, for instance. My thought was to extract a set of distinct instrument names, and do a v-if comparing the member's instrument name to the iterated set value, and only display the member if the member's data property instrumentName matches the current value of the instrument names set. With the code below, I'm getting an error "instNames is not defined". I'm still learning Vue and Nuxt, and am trying to get away from WebMatrix, the original platform for my website. The other thing I need is to attach an instrumentFilename (picture) to each distinct instrumentName. Any help is greatly appreciated!
<template>
<div class="block bg-blue-200 w-96 p-6 m-auto">
<table>
<tr v-for="inst in instNames">
<td>{{ inst.instrumentName }} <img :src="'/images/' + inst.instrumentFilename" >
<td v-for="member in members" :key="member.id">
<div v-if="member.instrumentName == inst.instrumentName"> </div>
<div>{{ member.firstname }} {{ member.lastname }} </div>
<div v-if="$auth.loggedIn" class="block">
<p v-if="!member.email == ' '" class="ml-10"> Email: {{ member.email }} </p>
<p v-if="!member.telephone == ' '" class="ml-10"> Home: {{ member.telephone }} </p>
<p v-if="!member.telephone2 == ' '" class="ml-10">Cell: {{ member.telephone2 }}</p>
<p v-if="!member.street == ' '" class="ml-10">Address: {{ member.street}}</p>
<p v-if="!member.city == ' '" class="ml-28">{{ member.city}}, {{ member.zip}}</p>
</div>
</td>
</tr>
</table>
</div>
</template>
<script>
export default {
async asyncData(context){
const { data } = await context.$axios.get('/api/members')
return {
members : data
}
},
computed: {
instNames: function() {
instNames = [...new Set(this.members.map(x => x.instrumentName))]
return instNames
}
}
}
</script>