gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:45:26 26 4
gpt4 key购买 nike

此代码导致开发者控制台出现错误:

$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 确实包含数据,并且它目的;它非常复杂,所以我不会用它来混淆问题,但她是一个概述图片

enter image description here

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

angular.min.js:83 TypeError: Cannot read property 'forEach' of undefined
at mapController.js:138
at Array.forEach ()
at a.$scope.AddCandidatesToCompannies (mapController.js:136)
at $scope.ProcessSearchResults (mapController.js:161)
at C (angular.min.js:91)
at C (angular.min.js:91)
at angular.min.js:92
at h.$eval (angular.min.js:100)
at h.$digest (angular.min.js:98)
at h.$apply (angular.min.js:101)
at f (angular.min.js:66)
at K (angular.min.js:70)
at XMLHttpRequest.y.onreadystatechange (angular.min.js:71)

有人能看到我做错了什么吗?

最佳答案

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}]

关于javascript - AngularJS无法读取未定义的属性 'forEach',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55880169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com