我要纠正警告
预期将在箭头函数array-callback-return中返回一个值。
我尝试添加return
,但问题仍然存在。
listTaskWorkflow.forEach(element => {
workflowDetail.department.departmentsList.find(department => {
if (department.idDept === element.idDept)
element.idDept = department.departmentName;
})
});
答案 0 :(得分:0)
find
希望您告诉它回电给您的物品是否是您要寻找的物品。要在该代码中使用它,您需要在idDept
中保留find
检查,然后使用它返回的数组元素:
listTaskWorkflow.forEach(element => {
const department = workflowDetail.department.departmentsList.find(department => department.idDept === element.idDept);
if (department) {
element.idDept = department.departmentName;
}
});
不过,另一种选择是使用for-of
循环:
listTaskWorkflow.forEach(element => {
for (const department of workflowDetail.department.departmentsList) {
if (department.idDept === element.idDept) {
element.idDept = department.departmentName;
break;
}
}
});
如果愿意,也可以使用for-of
代替forEach
:
for (const element of listTaskWorkflow) {
for (const department of workflowDetail.department.departmentsList) {
if (department.idDept === element.idDept) {
element.idDept = department.departmentName;
break;
}
}
}