当要过滤数组,关键字有多个怎么办
keyList = new Map(); // 保存你的关键字,别的数据结构也可以
handelColumKeyFilter(key, index) {
if (key === '') {
this.keyList.delete(index);
} else {
this.keyList.set(index, key);
}
if (this.keyList.size === 0) {
// do sth..
} else {
// arr.reduce-> get an union set but not a intersection.
this.firstInitPage = this.arr.reduce((ary, item, curindex) => {
this.keyList.forEach((v, i) => {// 循环你的keylist
if (item[i].indexOf(v) !== -1) {
if (!ary.find(k => k === item)) {
ary.push(item); // 并集push
}
}
});
return ary;
}, []);
}
}