[英]Correct warning : "Expected to return a value in arrow function array-callback-return "
I want to correct the warning我想更正警告
Expected to return a value in arrow function array-callback-return".
预期在箭头函数数组回调返回中返回一个值”。
I tried adding return
but the problem still exists.我尝试添加
return
但问题仍然存在。
listTaskWorkflow.forEach(element => {
workflowDetail.department.departmentsList.find(department => {
if (department.idDept === element.idDept)
element.idDept = department.departmentName;
})
});
find
expects you to tell it whether the item it's calling you back with is the item you're looking for. find
期望您告诉它它正在给您回电的项目是否是您正在寻找的项目。 To use it in that code, you'd leave the idDept
check in the find
but then use the array element it returns:要在代码中使用它,你会离开
idDept
在检查find
,但然后用它返回数组元素:
listTaskWorkflow.forEach(element => {
const department = workflowDetail.department.departmentsList.find(department => department.idDept === element.idDept);
if (department) {
element.idDept = department.departmentName;
}
});
Another option, though, would be to use a for-of
loop:不过,另一种选择是使用
for-of
循环:
listTaskWorkflow.forEach(element => {
for (const department of workflowDetail.department.departmentsList) {
if (department.idDept === element.idDept) {
element.idDept = department.departmentName;
break;
}
}
});
You could use for-of
instead of forEach
as well if you wanted:如果需要
for-of
您也可以使用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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.