此代码在开发人员控制台中导致错误:

$scope.AddCandidatesToCompannies = function()
{
    console.table($scope.candidates);
    Object.entries($scope.candidates).forEach(candidate =>
    {
        candidate.jobs.forEach(job =>
        {
            var company_id = job['company_id'];

            Object.entries($scope.companies).forEach(company =>
            {
                if (company['company_id'] == company_id)
                {
                    console.log('match');
                };
            });
        });
    });
};   // AddCandidatesToCompannies()
$scope.candidates 是否包含数据,并且一个对象;它很复杂,所以我不会在上面打乱它,但她是一张概述照片

javascript - AngularJS无法读取未定义的属性 'forEach'-LMLPHP

语句Object.entries($scope.candidates).forEach(candidate =>给出了



谁能看到我做错了吗?

最佳答案

Object.entries返回带有键,值对的数组中的数组。
看起来您想拥有类似的功能Object.values($scope.candidates)
例:

Object.entries($scope.candidates) == [[45,{candidate_id:45}],[46,{candidate_id:46}]]
Object.values($scope.candidates) == [{candidate_id:45}, {candidate_id: 46}]

09-26 05:17