我有一个 json 数据集, Angular 为
$scope.data = [{
call_id: '1',
title: 'test',
start: new Date(elem.call_date),
backgroundColor: "#9f1eab",
borderColor: "#9f1eab",
filterByCheckbox: 'filterOne'},
{
call_id: '1',
title: 'test',
start: new Date(elem.call_date),
backgroundColor: "#9f1eab",
borderColor: "#9f1eab",
filterByCheckbox: 'filterTwo'
}];
现在我有 3 个 checkox
filterOne
filterTwo
filterThree
现在我想根据上述 3 个复选框选择来过滤 $scope.data
。
$scope.data
中要过滤的列是 filterByCheckbox
上面是我的数据集,其中包含具有 filterByCheckbox
列的记录列表,我想根据该列过滤数据。
如果选中前 2 个复选框,则应在包含 filterOne
和 filterTwo
的列 filterByCheckbox
上过滤$scope.data
> 值。
如何在 AngularJS 中实现这一点?
我已经尝试过:
$filter('filter')($scope.data, { filterByCheckbox: 'filterTwo' })
但它仅适用于一个复选框。
最佳答案
$scope.filterdData=[];
angular.forEach($scope.data,function (val,key){
if(($scope.filterOne && val.filterByCheckbox==='filterOne')||($scope.filterTwo && val.filterByCheckbox==='filterTwo')||($scope.filterThree && val.filterByCheckbox==='filterThree')){
$scope.filterdData.push(val);
}
});
关于javascript - 基于复选框选择的具有不同值的单列的 AngularJs 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43200395/