简体   繁体   English

正确警告:“预期在箭头函数数组回调返回中返回一个值”

[英]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.

相关问题 预期在箭头函数array-callback-return中返回一个值 - Expected to return a value in arrow function array-callback-return 预期在箭头函数结束时返回一个值:array-callback-return - Expected to return a value at the end of arrow function: array-callback-return 预期在箭头函数array-callback-return的末尾返回一个值 - Expected to return a value at the end of arrow function array-callback-return React:箭头函数需要返回值array-callback-return - React: Arrow function expected a return value array-callback-return 如何修复警告“预计在箭头 function 数组回调返回中返回一个值” - How fix warning “Expected to return a value in arrow function array-callback-return” 反应警告 预期在箭头函数数组-回调-返回结束时返回一个值 - react warning Expected to return a value at the end of arrow function array-callback-return 为什么我收到此警告 159:35 警告预计将在箭头 function 数组回调返回的末尾返回一个值? - Why i am getting this warning 159:35 warning Expected to return a value at the end of arrow function array-callback-return? 期望在过滤函数的箭头函数array-callback-return结尾处返回一个值 - Expected to return a value at the end of arrow function array-callback-return on filter function 如何修复“预期在箭头函数数组回调返回中返回一个值”? - How to fix "Expected to return a value in arrow function array-callback-return"? 如何解决警告“预期在此函数array-callback-return中返回值” - How to fix warning “ Expected to return a value in this function array-callback-return ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM