[英]issue:comparing and object with array of objects
我有一种情况,我需要将名为“名称”的对象属性与具有相同名称的字符串数组进行比较,并根据名称获取比较值的长度。 我不明白我需要比较什么。
这是我的代码如下:
$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);
}
});
您应该这样写。
$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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.