Each user in our database can have specific skills. We have a list of available skills in our db and each has it’s own unique id. We need to be able to filter users to see which ones have the skill we are looking for. For example, show all Janitors.
We’re using vuejs and this filter is a computed property.
Here’s what I have so far:
filteredResults() {
return this.user.filter(user => this.skills.find(skill => user.skills.id == skills.id));
}
I think this is my problem "user.skills.id". I want to say: user.skills[*].id, but that’s not valid syntax.
How can I find my users where one of their skills has an id that matches my selected (in a search dropdown) skill.id?
Our data looks like this:
Users: [
user1: {
name: "Tom",
id: "12345",
skills: [
0: {
title: "Programmer",
id: "12345678"
},
1: {
title: "Janitor",
id: "6788012"
}
]
},
user2 {
name: "Bill",
id: "u0wb0fu3b",
skills: [
0: {
title: "Landscaper",
id: "234525"
},
1: {
title: "Janitor",
id: "6788012"
}
]
}
]
SearchedSkills: [
0: {
title: "Landscaper",
id: "234525"
},
]
2
Answers
You can use
Array#some
.