2016-07-08 92 views
0

我有一个场景,我需要比较名为'name'的对象属性和具有相同名称的字符串数组,并获取基于名称的比较值的长度。我不明白我需要比较什么。问题:比较和对象与对象数组

这里是我下面的代码:

$scope.pushRec=[]; 
    //----comparing response and response.club properties 
    angular.forEach($scope.aResponse, function(value, key) { 
     $scope.aClub=value.club; 
     console.log($scope.aClub); 
     console.log(value.recruiter); 
     $scope.aResRec=value.recruiter; 
    }); 
    //----if it matches push in to pushRec 
    angular.forEach($scope.aClub, function(value, key) { 

     console.log(value.recruiter); 
     $scope.aRec=value.recruiter; 
      console.log($scope.aClub); 
     if($scope.aResRec[0] == $scope.aRec){ 
      $scope.pushRec.push($scope.aClub); 
      console.log($scope.pushRec.length); 
     } 

    }); 
+0

您可以在代码中添加注释以获得更好的主意。 –

+0

@VivekSingh添加评论 – anub

回答

0

你应该这样写。

$scope.pushRec=[]; 
    //----comparing response and response.club properties 
    angular.forEach($scope.aResponse, function(value, key) { 
     $scope.aClub= angular.copy(value.club); 
     console.log($scope.aClub); 
     console.log(value.recruiter); 
     $scope.aResRec=angular.copy(value.recruiter); 
    }); 
    //----if it matches push in to pushRec 
    angular.forEach($scope.aClub, function(value, key) { 

     console.log(value.recruiter); 
     $scope.aRec=value.recruiter; 
      console.log($scope.aClub); 
     if($scope.aResRec[0] === $scope.aRec){ 
      $scope.pushRec.push($scope.aClub); 
      console.log($scope.pushRec.length); 
     } 

    }); 
+2

请编辑更多信息。仅限代码和“尝试这个”的答案是不鼓励的,因为它们不包含可搜索的内容,也不解释为什么有人应该“尝试这个”。我们在这里努力成为知识的资源。 – abarisone