2016-12-26 1 views
0

API의 데이터를 드롭 다운에 표시하려고합니다 (Department Full Name). 하나의 값을 표시 할 수 있지만 여러 값을 표시 할 수는 없습니다. 내가 어디가 잘못 됐는지 말해 줄 수 있니?다른 배열의 여러 값을 드롭 다운에 추가하는 방법은 무엇입니까?

json 배열에서 선택 드롭 다운으로 값을 가져 오려고합니다. 드롭 다운으로 들어가기 원하는 값은 shortname, 학기섹션입니다. 나는 shortName 만 표시 할 수 있지만 다른 2 개의 값은 표시 할 수 없습니다.

index.controller.js

$http.get('https://student.herokuapp.com/department/') 
     .success(function(response){ 

      $scope.deptDetails=response.department; 
     // console.log($scope.deptDetails); 
      deptLen=response.department.sections.length; 
      console.log(deptLen); 

      for(var i=0;i<deptLen;i++){ 

       $scope.deptDetails.push({"_id":response.department._id, 
               "shortName":response.department.shortName, 
               "section":response.department.sections[i].section, 
               "semester":response.department.sections[i].semester}); 
      } 

     }); 

JSON 배열 여기

{ 
"department": { 
"_id": "585955afce1a5e0011a2ecf5", 
"collegeId": "58295efb836f8611d5e3e4cb", 
"fullName": "Compcsuter Science", 
"shortName": "CS", 
"numberOfSemesters": "8", 
"semesterYearScheme": "Semester", 
"programName": "UG", 
"numberOfSections": "1", 
"sections": [ 
     { 
    "_id": "585fb137bf29882207752552", 
    "collegeId": "585e53c6729e5c2214b97a0f", 
    "departmentId": "585fb137bf29882207752546", 
    "semester": 4, 
    "section": "C", 
    "syllabus": [], 
    "teachers": [], 
    "students": [], 
    "createdBy": "58332b90a7986c09b7e81980", 
    "createdAt": "2016-12-25T11:44:55.445Z", 
    "__v": 0 
     } 
    ] 

plnkr

+0

는 당신이 언급하는 드롭 다운? – Sajeetharan

+0

@Sajeetharan 오 죄송합니다. 나는 Departname 성을 언급하고 있습니다. – HebleV

답변

2
당신은이 작업을 수행 할 수

,

입니다 당신의 plunker에서

편집

response.data.department.sections.forEach(function(key){ 
      $scope.displayValues.push(response.data.department.shortName + " "+ key.section + " "+key.semester); 

    }) 

DEMO

+0

노력에 감사드립니다. CS C 4 – HebleV

+0

@HebleV와 같이 한 줄에 인쇄하려면 어떻게합니까? https://plnkr.co/edit/SkzfOqyZ1frxtamrBfQJ?p=preview – Sajeetharan

+0

Upvote를 확인하십시오. 이것은 질문을 읽은 후 내 마음에 들었던 것입니다. –