I have two arrays: users and projects. IDs in both are unique numbers. A project can have more than one owner, so in projects I have an array of user IDs named ownersId that link to the id of users in users, as seen here:
export const users = [{
id: 1,
givenName: 'Alexander',
surname: 'Kelly',
initials: 'AK'
}, {
id: 2,
givenName: 'Karen',
surname: 'Jones',
initials: 'KJ'
}, {
id: 3,
givenName: 'Casey',
surname: 'Fields',
initials: 'CF'
}, {
id: 4,
givenName: 'Sam',
surname: 'Johns',
initials: 'SJ'
}, {
id: 5,
givenName: 'Thomas',
surname: 'Smith',
initials: 'TS'
}, {
id: 6,
givenName: 'Jack',
surname: 'Jenson',
initials: 'JJ'
}];
export const projects = [{
id: 1,
name: 'Project 1',
ownersId: [
1,
2,
5,
6,
]}, {
id: 2,
name: 'Project 2',
ownersId: [
1,
3,
]}, {
id: 3,
name: 'Project 3',
ownersId: [
1,
2,
4,
3,
]}, {
id: 4,
name: 'Project 4',
ownersId: [
1,
]}, {
}]
What I am trying to do is loop over the details of project which I have successfully done using v-for. What I am stuck on is displaying a loop within the loop that displays all the users names using the IDs in the ownersId field.
<template>
<div class="demo">
<div
v-for="project in projects"
v-bind:key="project.id"
>
<h4><strong>{{ project.name }}</strong></h4>
<div v-if="project.ownersId" >
Shared with {{ project.ownersId.length }} others
</div>
<div>
<!-- Loop of the list of names from IDs goes here -->
</div>
</div>
</div>
</template>
<script>
import { projects } from '../data/example';
import { users } from '../data/example';
export default {
name: "Demo",
data() {
return {
projects,
users,
}
}
}
</script>