Ich versuche, eine Dropdown-Liste zu erstellen, und wenn ich es erstelle, möchte ich nach einem Feld filtern. Zum Beispiel:Herausfiltern in for-Schleife
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="cost" ng-options="x.cost for x in costs">
</select>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.costs = [{'cost': 1, 'difficulty' : 3}, {'cost': 2, 'difficulty' : 2}, {'cost': 3, 'difficulty' : 3}];
});
</script>
<p>This example shows how to fill a dropdown list using the ng-options directive.</p>
</body>
</html>
Wie würde ich durch difficulty
in diesem Beispiel filtern?
$scope.myFilter = function(x) {
return x.difficulty >= 3;
}
und wenden es in ng-options
wie folgt aus::
<select ng-model="cost" ng-options="x.cost for x in costs | filter : myFilter">
</select>
Demo unter:
Ist es möglich, so etwas wie
ng-options="x.cost for x in costs where x.difficulty >= 3"
Es klingt wie Sie einen [Angular Filter] verwenden möchten (https://docs.angularjs.org/api/ng/filter/filter). – Skylar