2016-08-16 35 views
0

我有我使用一個搜索控制器工作:角NG重複不與搜索控制器

function searchRes($scope, $http, API, CarDetailService, $state){ 

    $scope.$watch('search', function() { 
    fetch(); 
    }); 

    $scope.currentPage = 1; 
    $scope.pageSize = 5; 

    function fetch(){ 
    $http.get(API + "/search/" + $scope.search) 
    .then(function(response){ 
     $scope.details = response.data; 
    }); 
    } 

    $scope.select = function(){ 
    this.setSelectionRange(0, this.value.length); 
    } 

    $scope.selectCar = function(carId) { 
    CarDetailService.setCar(carId); 
    $state.go('taskDetails'); 
    }; 

} 

下面是HTML:

<div ng-controller="searchRes" class="mainSearch"> 

    <div class="searchBar"> 
    <input type="text" ng-model="search" onclick="select()" placeholder="Enter Search Term" autofocus /> 
    </div> 

    <div ng-repeat="res in details.Search"> 
    <div>{{ res['Display Name'] }}</div> 
    </div> 

</div> 

我曾嘗試:

ng-repeat="res in details" 
ng-repeat="res in response.data" 
ng-repeat="res in data" 
ng-repeat="res in response" 
ng-repeat="res in response.data.Results" 
ng-repeat="res in details.data.Results" 

這裏是一個什麼形象API返回(data.Results):

enter image description here

編輯當我做了一個console.log(response);我可以看到所有的JSON數據返回(data.Results)

我知道我顯然不正確調用數據,但我不知道還有什麼嘗試,我猜就是爲什麼我在這裏。

+0

'$ scope.fetch =功能()'? –

+0

'response.data'的結構是什麼?數組?一個東西?請發佈。 – SteamDev

+0

data.Results。它是一個對象,在該對象內部是我試圖循環訪問的數組。我編輯了我的問題。感謝您指出了這一點。我忘了添加它。 – agon024

回答

3

你需要ng-repeat="res in details.Results"

+0

非常感謝您的幫助。豎起大拇指。 – agon024