当选择某一项时,需要把指定项的值存储起来后使用
e.g:
el-select 选中美国海外仓(USA)
,需要把 arr 数组中的每一项的 key(属于 USA 下的数据
)传回给后端
let arr = [
{
value: "波兰仓库03",
key: 1406920626937065500,
platform: "Mbb",
},
{
value: "工业城仓",
key: 1430742236437651500,
platform: "Hx",
},
{
value: "安大略仓",
key: 1430742236580257800,
platform: "Hx",
},
{
value: "富勒顿仓",
key: 1430742236643172400,
platform: "Hx",
},
{
value: "LAX99",
key: 1431153262349910000,
platform: "Aybases",
},
{
value: "TESTO1",
key: 1431153262404436000,
platform: "Aybases",
},
{
value: "洛杉矶1号仓",
key: 1432520453796274200,
platform: "Aybases",
},
{
value: "洛杉矶2号仓",
key: 1432520453817245700,
platform: "Aybases",
},
];
let choseValue = "USA";
// 触发下单人/团队下拉框
let fun1 = function changeSubscriber(val) {
if (val.length === 0) {
this.searchKey = [];
this.keys = [];
}
// console.log(val,'当前选中的值');
let choseValue = val.join();
// let keys = [];
if (["USA", "Europe"].includes(choseValue)) {
for (let i = 0; i < this.subscriberList.length; i++) {
let ele = this.subscriberList[i];
if (choseValue === "USA") {
if (["Mbb", "Hx"].includes(ele.platform)) {
this.keys.push(ele.key);
}
} else if (choseValue === "Europe") {
if (["Mbb", "Aybases"].includes(ele.platform)) {
this.keys.push(ele.key);
}
}
}
} else {
this.searchKey = val;
}
// console.log(this.keys,'keys')
};
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
优化写法
let fun2 = function changeSubscriber(val) {
let choseValue = val.join();
let _map = {
USA: ["Mbb", "Hx"],
Europe: ["Mbb", "Aybases"],
};
// Object.key(_map) 返回可枚举属性组成的数组, ['USA', 'Europe']
if (Object.keys(_map).includes(choseValue)) {
this.keys = this.subscriberList.filter((v) => {
// 返回为真的这一项
return _map[choseValue].includes(v.platform);
});
// return
}
this.searchKey = choseValue ? val : [];
// 没值的时候是false,取反就是true
if (!choseValue) {
this.keys = [];
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
在线编辑 (opens new window)
上次更新: 2021/11/14, 15:48:46