2016-12-22 1 views
1

개인 프로젝트에서 일하고 있으며 마지막 부분에서 그루터기가 있습니다. 내 데이터베이스에있는 회사의 이름과 같은 회사의 데이터 만 가져 오려고합니다.배열이 서로 다른 인덱스에 있어도 두 배열에 동일한 값이 포함되어 있는지 어떻게 확인할 수 있습니까?

$http.get('//localhost:8081/api/jobs').then(function(res) { 
    $scope.data = res.data; //data from the database 
    $scope.size = $scope.data.length; //length 132 
    for (var i = 0; i < $scope.size; i++) { 
     if ($scope.data[i].glassdoor !== null && $scope.data[i].glassdoor !== undefined) { 
      $scope.hasGlassdoor = []; 
      for (var i = 0; i < $scope.size; i++) { 
       if ($scope.data[i].glassdoor !== null && $scope.data[i].glassdoor !== undefined) 
        $scope.hasGlassdoor.push($scope.data[i]); 
      } 

      //Get the companies name that have glassdoor 
      $scope.company = []; 
      for (var j = 0; j < $scope.hasGlassdoor.length; j++) { 
       $scope.company.push($scope.hasGlassdoor[j].company); 
      } 

      //Create the URL calls for my glassdoor api 
      $scope.url = []; 
      for (var x = 0; x < $scope.company.length; x++) { 
       $scope.url.push('//localhost:8081/api/glassdoor/' + $scope.company[x]); 
      } 
      //For example : '//localhost:8081/api/glassdoor/A9.com' 

      //Get the Glassdoor data 
      var company = $scope.company; 
      for (var j = 0; j < $scope.url.length; j++) { 
       $http.get($scope.url[j]).then(function(response) { 
        $scope.gData = response.data; 
        $scope.gSize = $scope.gData.length; 
        $scope.gName = []; 

        //Get the names of the companies that glassdoor returns 
        for(var x = 0; x < $scope.gSize; x++){ 
         if ($scope.gData[x] !== null && $scope.gData[x] !== undefined) { 
          if ($scope.gData[x].name !== null && $scope.gData[x].name !== undefined) { 
            $scope.gName.push($scope.gData[x].name); 
          } 
         } 
        } 
        //Now I'm trying to only get the names of the companies that are in my variable company 
        //For example '//localhost:8081/api/glassdoor/6sense 
        //returns data for 6sense, and a company named 6sense Technologies 
        //I'm trying to just get the data of 6sense 

        // 
        //  TODO 
        // 


        // My try using loDash returns undefined. 
        // I'm trying to see if $scope.gName is in var Company. 
        //if(_.includes(company, $scope.gName)){ 
        // gd.push($scope.gName); 
        //} 

       }); //this is what is calling the glassdoor api 
      }//end of the for loop for url. 
     } //if statement to check for null 
    } //first for loop 
}).catch(function(error, res) { 
    console.log("Error:", error, res); 
}); 

가 지금 내가 너무 작은 목록에서 일하고 있어요 :

끝에 내 목표는 하나 개

Call one: $http.get('//localhost:8081/api/jobs').then(function(res) 
    Call two: localhost:8081/api/glassdoor/ 

전체 코드에 다음과 같은 두 가지 통화에서 얻은 두 jsons을 병합하는 것입니다 이 문제를 해결할 수 있습니다.

은 글래스 도어 호출을 다루는
[ 
    { 
     "company": "23andMe" 
     "glassdoor":"https://www.glassdoor.com/Overview/Working-at-23andMe-EI_IE145899.11,18.htm" 

"img":"https://www.23andme.com/static/img/icons/logo_alt.96cf7888b73d.svg" 
     "international":null 
     "link":"https://www.23andme.com/careers/" 
     "location":"Mountain View, CA" 
     "secondary":null 
     "third":null 
     "id":145899, 
     "name":"23andMe", 
     "website":"www.23andme.com", 
     "isEEP":true, 
     "exactMatch":true, 
     "industry":"Biotech & Pharmaceuticals", 
     "numberOfRatings":27, 
     "squareLogo":"https://media.glassdoor.com/sqll/145899/23andme-squarelogo.png", 
     "overallRating":"4.2", 
     "ratingDescription":"Very Satisfied", 
     "cultureAndValuesRating":"4.5", 
     "seniorLeadershipRating":"3.6", 
     "compensationAndBenefitsRating":"4.0", 
     "careerOpportunitiesRating":"3.4", 
     "workLifeBalanceRating":"4.3", 
     "recommendToFriendRating":80, 
     "sectorId":10005, 
     "sectorName":"Biotech & Pharmaceuticals", 
     "industryId":200021, 
     "industryName":"Biotech & Pharmaceuticals", 
     "featuredReview":{ 
     "attributionURL":"https://www.glassdoor.com/Reviews/Employee-Review-23andMe-RVW11447587.htm", 
     "id":11447587, 
     "currentJob":true, 
     "reviewDateTime":"2016-08-03 15:05:20.157", 
     "jobTitle":"Customer Care Reporesentative", 
     "location":"Mountain View, CA", 
     "jobTitleFromDb":"Customer Care Reporesentative", 
     "headline":"Customer Care Representative", 
     "pros":"the environment-everyone is extremely genuine, smart, and friendly. management is very understanding and open. Executives are transparent with everything going on in the company\r\nbenefits-free gym, food every day, snacks, great health coverage, rooftop access, etc\r\nworkspace-facilities does a phenomenal job at keeping everything extremely clean and fixes all issues ASAP. I don't feel like I'm sitting a boring desk job all day, it's a fun place to be", 
     "cons":"Traffic through downtown mountain view can suck and the train can be kind of loud (I cannot think of a legitimate con, everything is awesome here)", 
     "overall":5, 
     "overallNumeric":5 
     }, 
     "ceo":{ 
     "name":"Anne Wojcicki", 
     "title":"CEO", 
     "numberOfRatings":15, 
     "pctApprove":100, 
     "pctDisapprove":0 
     } 
    } 
] 

Server.js :

//Glassdoor api call 
app.get('/api/glassdoor/:company', function(req, res, next) { 
    var company = req.params.company; 
    requestify.get('https://api.glassdoor.com/api/api.htm?t.p=PRODUCT&t.k=KEY&userip=0.0.0.0&useragent=&format=json&v=1&action=employers&q=' + company).then(function(response) { 
     // Get the response body (JSON parsed or jQuery object for XMLs) 
     gData = response.getBody(); 
     gData = gData.response.employers; 
     res.json(gData); 
    }); 



}); 

답변

0

정렬 배열, 다음을 열거 끝에

내 목표는 내 완성 된 JSON으로이하는 것입니다. 이전 === 현재 당신은 속임수를 가지고 있습니다.

0

이것은 내가 어떻게 해결했는지입니다.

app.get('/api/glassdoor/:company', function(req, res, next) { 
    var company = req.params.company; 
    requestify.get('https://api.glassdoor.com/api/api.htm?t.p=PRODUCT&t.k=KEY&userip=0.0.0.0&useragent=&format=json&v=1&action=employers&q=' + company).then(function(response) { 
     // Get the response body (JSON parsed or jQuery object for XMLs) 
     gData = response.getBody(); 
     gData = gData.response.employers; 
     //What I added to only send the data of the companies that where like 'company' 
     for (var i = 0; i < gData.length; i++) { 
      if (gData[i].name === company) { 
       gData = gData[i]; 
       res.send(gData); 
      } 
     } 
    }); 
}); 

전체적인 질문에 대한 답은 아니지만 그게 내 문제를 해결 한 방법입니다.

관련 문제