处于写入所选过滤器的状态:
state = {
filters: [],
};
有项目清单:
const json = [
{action : true, new : true, name : 'Морський'},
{action : true, new : false, name : 'Дольче Віта' },
{action : false, new : false, name : 'Спекотний сезон' },
{action : false, new : true, name : 'Уікенд' },
]
如何通过选定的过滤器过滤项目?具有过滤器的状态如下所示:filters ["new", "action"]
const result = json.filter(x => filters.every(y => x[y]));
const filters = ["new", "action"];
const json = [
{ action: true, new: true, name: "Морський" },
{ action: true, new: false, name: "Дольче Віта" },
{ action: false, new: false, name: "Спекотний сезон" },
{ action: false, new: true, name: "Уікенд" }
];
const result = json.filter(x => filters.every(y => x[y]));
console.log(result)