function filter(condition, data){
return data.filter( item => {
return Object.keys( condition ).every( key => {
return String( item[ key ] ).toLowerCase().includes(
String( condition[ key ] ).trim().toLowerCase() )
})
})
}
let condition = {type:'第一个类型',name:'小李'};
let conditions = {type:'第一个类型'};
let searchList = [
{type:'第一个类型',name:'小张'},
{type:'第一个类型',name:'小刘'},
{type:'第二个类型',name:'小刘'},
{type:'第一个类型',name:'小李'},
]
let c = filter(condition,searchList)
console.log('多条件查询c====>',c)
let d = filter(conditions,searchList)
console.log('单条件查询d====>',d)
searchList为需要被查询的数据、condition为查询条件,根据不同情景添加条件,实现前端查询
结果