I have an array of objects where I need to filter based on a dropdown selection.
const itemsList=[{
"id":"123",
"problems":{
"causes":[
{
"SSEnabled": true,
"IndusEnabled": false,
"LogEnabled": true
}
]
}
},
{
"id":"234",
"problems":{
"causes":[
{
"SSEnabled": false,
"IndusEnabled": false,
"LogEnabled": true
}
]
}
}]
There is a dropdown to filter by SSEnabled cause with options "show", "nofilter", "exclude".
The goal is to filter the list based on the dropdown selection.
If "show" is selected for "SSEnabled", the item with "SSEnabled": true should be the result (i.e. id: "123").
If "exclude" is selected for "SSEnabled", the item with "SSEnabled": false should be the result (i.e. id: "234").
If "nofilter" is selected, the filter should be ignored (i.e. id: "123", id: "234").
filterList(filterType, filterValue, itemsList) {
// filterType: SSEnabled (dropdown type changed)
// filterValue: show, exclude, no filter
itemsList.map((items) => {
if (
items &&
items.problems &&
items.problems.causes &&
items.problems.causes.length
) {
items.problems.causes.filter((cause) => {
if (cause[filterType] === true && filterValue === 'show') {
return true;
}
if (cause[filterType] === false && filterValue === 'exclude') {
return true;
}
});
}
});
console.log(itemsList, 'filtered List');
}
However, the list is not being filtered as expected. Assistance with filtering is appreciated.