您能否使用以下javascript函数帮助修复棉绒错误。

错误:将此数组的“排序”操作移至单独的语句。

  item.EmployeeDetails = item.EmployeeDetails
                            .sort((a: IEmployeeDetails, b: IEmployeeDetails) => {
        if (a.employeeType < b.employeeType) {
            return 1;
        }
        if (a.employeeType > b.employeeType) {
            return -1;
        }
        return 0;
    });

最佳答案

sort()改变数组。参见https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype#Mutator_methods

因此,尝试省略赋值运算符:

item.EmployeeDetails.sort((a: IEmployeeDetails, b: IEmployeeDetails) => {
    if (a.employeeType < b.employeeType) {
        return 1;
    }
    if (a.employeeType > b.employeeType) {
        return -1;
    }
    return 0;
});

关于angular - Linting错误: Move this array "sort" operation to a separate statement,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52606401/

10-12 01:57