我需要根据多个值筛选一些数据。
Language
我是说,
title
和
slug
[
{
de: "4567uy55",
en: "654321",
lang: [
{
id: "654321",
language: "English",
title: "Title1"
},
{
id: "4567uy55",
language: "German",
title: "Title2"
}
],
slug: 'some-slug'
},
...
]
我现在拥有的返回所有拥有一个或部分过滤器的对象(如果title是
This is a title
,单词
this
应该匹配),但我需要返回包含所有对象的对象。
我使用一个对象flattner来获取一个对象中的所有属性和值,但是我不能让它按照我需要的方式进行过滤。
multiFilter = (arr, filters) => {
console.log(filters)
console.log(arr)
let newArray = []
for (let c of arr) {
let flatCourse = flatten(c)
for (let k in flatCourse) {
const keyArr = k.split('/')
const filterKeys = Object.keys(filters)
Object.keys(filters).map((key) => {
if (keyArr.includes(key)) {
const flatVal = flatCourse[k].toString().toLowerCase()
const filterVal = filters[key].toString().toLowerCase()
console.log(flatVal)
console.log(filterVal)
if (flatVal.includes(filterVal)) {
arr = []
arr.push(c)
newArray.push(c)
}
}
})
}
}
return newArray
}
过滤器如下:
[
language:["English"],
title: ["Some title"],
slug:["some slug"]
]