I have been working on a FAQ page that has categories and once you have selected a category, it shows questions users have asked. You can then select a question to display the answer. There are 7 categories and each has an array named "questionList" that has various amounts of questions. I am creating a search bar that will filter through ALL questions in each category and display the question and answer that matches the search. Right now the filtered list only displays the first categories questions....
Here is an example of how my data is setup
categoryList : [
{
category: 'Category Title',
questionList: [
{
question: 'Question',
answer: '<p>copy goes here</p>'
}, ...
]
},
{
category: 'Next Title',
questionList: [
{
question: 'Question',
answer: '<p>copy goes here</p>'
},
]
}, ...
I was looking at another stackoverflow solution and I really could not figure out how to have it function with my multiple nested arrays. Here is the html:
<div class="filtered" v-for="qa in filteredList">
<div class="filter-container">
<h3>{{ qa.question }}</h3>
<div v-html="qa.answer"></div>
</div>
</div>
and my computed function:
filteredList() {
for (i = 0; i < this.categoryList.length; i++) {
var list = this.categoryList[i];
for (j = 0; j < list.questionList.length; j++ ) {
return list.questionList.filter(qa => {
return qa.question.toLowerCase().includes(this.search.toLowerCase());
})
}
}
}
I'm not sure if I am even close to the correct solution or waaaay off here... please help!