私は、ユーザと興味のあるオブジェクトの配列を持っています。私はfilter
興味に基づいてリストにしたいと思います。ユーザーは複数の関心を持つことができ、選択した関心のチェックボックスをオンにすると、その関心に基づいてリストが除外されます。私はng-repeatに基本的なフィルタを使用しましたが、うまくいきません。配列内の項目のリストを含む角度フィルタ
「スポーツ」を選択すると、「John」と「Rosaline」が表示されます。 「movies」と「reading」を選択すると、3人のユーザー全員が表示されます。 以下は私のコードです。
Plunker:https://plnkr.co/edit/A0ojO3MH8rDhFJVXlEAs?p=preview
ビュー:
<div ng-app="myApp" ng-controller="myController" style="padding:20px">
<input type="checkbox" ng-model="selection.reading" ng-true-value="'reading'" ng-false-value="''">reading
<input type="checkbox" ng-model="selection.sports" ng-true-value="'sports'" ng-false-value="''">sports
<input type="checkbox" ng-model="selection.movies" ng-true-value="'movies'" ng-false-value="''">movies
<br><br>
Selected Values: {{selectedValues}}
<hr>
<div ng-repeat="d in data | filter: selectedValues">
<h4>
Name: {{d.user}}
</h4>
<h4>
Interests: {{d.interests}}
</h4>
<hr>
</div>
コントローラー:
$scope.selection = {};
$scope.data = [
{
user: "John",
interests: ["reading","sports","movies"]
},
{
user: "David",
interests: ["movies","reading"]
},
{
user: "Rosaline",
interests: ["sports","movies"]
}
];
$scope.$watchCollection('selection', function() {
$scope.selectedValues = [];
angular.forEach($scope.selection, function (value, key) {
if (value) {
$scope.selectedValues.push(value);
}
});
});
見てくださいhttp://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs/21169596#21169596 – Manish