Angular checkbox filtering data list

后端 未结 2 1806
太阳男子
太阳男子 2021-01-28 02:10

Seen a few options for filtering data via checkboxes but it all seems fairly overly complicated for something I\'d expect Angular to do easily.

Take a nose at http://pln

2条回答
  •  广开言路
    2021-01-28 02:36

    Here is a solution; showing diffs only:

    In index.html modify the relevant lines as follows:

  • ...
  • ...
  • In script.js add:

    $scope.checkbox = {};
    var showAll = true;
    $scope.searchByCheckbox = function(result) {
        return showAll || $scope.checkbox[result.provider.providerId];
    };
    $scope.$watch("checkbox", function(newval, oldval) {
        showAll = true;
        angular.forEach($scope.checkbox, function(val) {
            if( val === true ) showAll = false;
        });
    }, true);
    

    (EDIT) Changed the key to $scope.checkbox to providerId. Filter starts disabled, so all entries are shown.

    Good luck!

提交回复
热议问题