我有多種選擇的廣告系列,當我選擇新客戶時,我希望廣告系列的範圍限定爲選定的客戶。篩選ng選項時,如何取消選擇所有篩選出的選項?
該過濾器按預期工作,但campaigns
的ng-model
可能包含隱藏過濾器的活動。
我希望所有過濾掉的廣告系列選項在不再處於選中狀態時都會被取消選中。
這裏是我的過濾器:
angular.module('MyApp')
.filter('campaignFilter', function(){
return function(options, client_ids, $scope) {
if (client_ids == null) {
return options;
} else {
filtered = [];
angular.forEach(options, function(option){
if (client_ids.indexOf(option.client_id) > -1) {
filtered.push(option);
} else {
idx = $scope.filter["campaign.id"].indexOf(option.client_id);
if idx > -1 {
$scope.filter["campaign.id"].splice(idx, 1);
};
};
});
return filtered;
}
}
});
更新:
我有$範圍過濾對象,我需要過濾廣告活動時進行更新。
$scope.filter["campaign.id"] = [1,2,3]
當選擇了一個客戶端,我想刪除從$scope.filter["campaign.id"]
所有系列ID不屬於該客戶端。
當我將範圍傳遞給過濾器時,$scope.filter
爲空。那麼我怎樣才能訪問範圍模型?
是什麼'deselected'是什麼意思?你所顯示的是一個過濾器 – charlietfl 2014-09-22 14:39:04
對不起。我的意思是ng-model是通過刪除所有被篩選器隱藏的選項來更新的。 – astephenb 2014-09-22 14:59:50