2016-05-09 26 views
0

我有軌道和地方被推入搜索結果。我只想顯示曲目。 _type的地方是"system.place"和軌道是"system.tracking"。儘管我有一個if語句來檢查搜索的每個結果,但它仍然顯示所有結果。任何輸入都會有幫助。顯示特定的過濾搜索結果

$scope.trackSearchChanged = function(searchText) { 
    if (searchText == '') { 
    $scope.trackSearchResults = []; 
    } 
    else { 
    Service.typeAheadSearch(searchText, 20).then(function (response) { 
     angular.forEach(response.results, function (track, index) { 
     if (track._type != "system.place") { 
      $scope.trackSearchResults = response.results; 
     } 
     }); 
    }); 
    } 
}; 

回答

1

爲了使您的forEach功能過濾嘴的,你必須創建第二個陣列把你需要的值。

Service.typeAheadSearch(searchText, 20).then(function (response) { 
    var places = []; 
    angular.forEach(response.results, function (track, index) { 
    if (track._type != "system.place") { 
     places.push(track); 
    } 
    }); 
    $scope.trackSearchResults = places; 
}); 
+0

解決了這個問題。這是一個簡單的修復。謝謝! – daveskylark