我有一些複選框,並在檢查,表格過濾器值。但是如果我選擇active和draft,它不會顯示任何內容,因爲它正在實現AND邏輯,所以我需要使用OR邏輯的過濾器。角度過濾器使用OR而不是AND邏輯
<div class="clearfix">
<input data-ng-model="active" data-ng-true-value="active" class="pull-left" type="checkbox" id="active"/>
<label class="pull-left" for="active">Active</label>
</div>
<div class="clearfix">
<input data-ng-model="draft" data-ng-true-value="draft" class="pull-left" type="checkbox" id="draft"/>
label class="pull-left" for="draft">Draft</label>
</div>
<table class="table">
<tr ng-repeat="campaign in dashboard.campaigns | filter:all | filter:active | filter:draft">
<td>{{campaign.name}}</td>
<td>{{campaign.startDate}}</td>
<td>{{campaign.endDate}}</td>
<td>{{campaign.status}}</td>
<td>{{campaign.tasks}}</td>
</tr>
編輯: 這裏是解決
app.filter('byStatus', [function() {
return function (campaigns, active, draft) {
var tempCampaigns = [];
angular.forEach(campaigns, function (campaign) {
if(campaign.status == active || campaign.status == draft){
tempCampaigns.push(campaign);
}
});
return tempCampaigns;
};
}]);
<tr ng-repeat="campaign in dashboard.campaigns | byStatus:active:draft">
THX所有;)
[如何在angularJS中篩選多個值(OR操作)]的可能重複(http://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs) – sloth
這只是我正在尋找的東西,thx:D – Arcagully