代码段

filter多条件过滤

前端实现过滤 过滤条件为空的字段需要删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
let condition = {
supplierCode: '123',
materialCode: '333'
}
let tableData = [
{
supplierCode: '123',
materialCode: '333'
},
{
supplierCode: '123456666',
materialCode: '333'
}
]

let queryTableData = []

function getQueryList() {
let tempFilter = {};
for (let key in condition) {
if (condition[key]) {
tempFilter[key] = condition[key];
}
}
queryTableData = tableData.filter((item) => {
let flag = false;
for (let i in tempFilter) {
if (tempFilter[i]) {
if (item[i] === tempFilter[i]) {
flag = true;
} else {
flag = false;
break;
}
}
}
if (flag) {
return item;
}
});
}

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2019-2023 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信