categories.location数组的过滤方式如下:
const displayedCategories = categories.filter(
(category) => category.location.indexOf(selectedLocation) >= 0
);
现在,其结构如下所示进行了更改,还有其他嵌套值。现在如何过滤值/标签? category.location.value.indexOf
不起作用。谢谢。
"location" : [
{
"value" : "London",
"label" : "London"
}
]
答案 0 :(得分:1)
尝试:
const displayedCategories = categories.filter(
(category) => category.location.some(loc=>loc.value==selectedLocation)
);