Filtering by multiple checkboxes in AngularJS

前端 未结 2 901
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 03:18

first time I\'ve posted a question on here, so apologies in advance if I breach any Stack Overflow etiquette! :-)

I\'m having a go at some AngularJS for the first ti

2条回答
  •  难免孤独
    2020-12-06 03:52

    I would bind all the checkboxes to one object say:

    app.js

    $scope.cartypes = {mini: false, compact:false};
    

    index.html

     Mini
     Compact
    

    And then create a custom filter function which returns whether the object contains all (I assume thats what you want) of the checked options.

    app.js

    app.filter('myfilter', function() {
        return function(items, options ) {
          // loop over all the options and if true ensure the car has them
          // I cant do this for you beacause I don't know how you would store this info in the car object but it should not be difficult
          return carMatches;
        };
    });
    

    Then you can add it to your template like this:

    index.html

提交回复
热议问题