JSFiddle
這應該現在的工作。
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<ul>
<li ng-repeat="x in names | filter : 'i'">
{{ x }}
</li>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
$scope.selectedCars = [1, 2, 5];
$scope.carsToDisplay = [];
for (var i = 0; i < $scope.selectedCars.length; i++) {
$scope.carsToDisplay.push($scope.names[$scope.selectedCars[i]]);
}
var p = document.getElementById('p');
p.innerHTML = $scope.carsToDisplay;
});
</script>
<p id="p">This example displays only the names containing the letter "i".</p>
</body>
</html>
我想你可能必須編寫自己的自定義過濾器才能做到這一點。看看[這個答案](http://stackoverflow.com/questions/22024631/angularjs-filter-based-on-array-of-strings)。 – Lex
@Lex是的,那個答案正是我正在尋找的,甚至有一個jsFiddle。謝謝。 –
你可以顯示你的名字json和你必須過濾哪些字段嗎? –