angle/ajax를 호출하여 API에서 값을 가져오고 결과를 기대하는 결과로 설정하려고합니다. 제안 제발 내 코드를 시도하지만, 내가 착각하고 어디는 두 번 호출 시간은 모르겠어anglejs를 사용하여 객체 형식으로 결과 얻기
$http.get('v1/res')
.success(function (data) {
$scope.results = [];
angular.forEach(data.data, function(value, key){
$scope.results.push({id: value.id});
$scope.results.push({text: value.name});
});
});
// 데이터를 얻는 당신을 위해 충분히 결과
$scope.results = [
{id: 1, text: 'A'},
{id: 2, text: 'B'},
{id: 3, text: 'C'},
{id: 4, text: 'D'},
{id: 5, text: 'E'},
{id: 6, text: 'F'},
{id: 7, text: 'G'},
{id: 8, text: 'H'},
];
다음과 같이 할 수 원하는대로 당신은 API 호출에서 얻는 결과는 같은 객체 인 경우? –
'$ scope.results.push ({ 'id': value.id, 'text': value.name});'? –
당신이 지금하고있는 방식은 id와 text를 두 개의 다른 객체로 푸시합니다. –