方法1:
typeMap: {
"设计": "0",
"商务": "1",
"供货": "2",
"施工": "3",
"调试": "4",
},
checkedLabels: ["设计", "商务", "供货"],
checkedLabels:[]
this.checkedLabels.forEach(label=>{this.applyType.push(this.typeMap[label]})
方法2:
const typeList = "0:设计进度,1:商务采购,2:供货进度,3:施工进度,4:调试进度";
const typeMap = typeList.split(",").reduce((acc, cur) => {
const [key, value] = cur.split(":");
acc[value] = key;
return acc;
}, {});
执行结束后,typeMap 将是一个对象{
"设计": "0",
"商务": "1",
"供货": "2",
"施工": "3",
"调试": "4"
}
this.checkedLabels.forEach((label) => {
const type = typeMap[label];
this.applyType.push(type);
});
前端简单常用映射方法,拿到对应的值
最新推荐文章于 2024-05-11 05:18:50 发布