javascript - Angular nested filters by checkbox -


i'm trying build small schedule app, displays events happening on 1 of 2 days. users able filter category/topic of events checkboxes. here demo: http://jsfiddle.net/qx3cd/201/

i want create nested filter, first allows users choose either day 1 or day 2, , filters through results category.

is there way perform nested filter angular?

js

function myctrl($scope) {  $scope.showall = true; $scope.checkchange = function() {     for(t in $scope.categoryarray){         if($scope.categoryarray[t].on){             $scope.showall = false;             return;         }     }     $scope.showall = true; };     $scope.myfunc = function(a) {    if($scope.showall) { return true; }     var sel = false;      for(cat in $scope.categoryarray){         var t = $scope.categoryarray[cat];         console.log(t);         if(t.on){             if(a.category.indexof(t.name) == -1){                 return false;             }else{                 sel = true;             }         }                }    return sel; };  $scope.categoryarray = [{ name: "a", on: false}, {name:"b", on: false}, {name:"c", on: false}, {name:"d", on: false}, {name:"e", on: false},             {name:"f", on: false}, {name:"g", on: false}, {name:"h", on: false}];  $scope.sessionarray = [{     "time": "9:00",     "day": "day 1",     "name": "session one",     "category": ["a", "b", "e", "d"] }, {     "time": "10:00",     "day": "day 1",     "name": "session two",     "category": ["a", "b", "c", "d"] }, {     "time": "11:00",     "day": "day 1",     "name": "session three",     "category": ["g", "f", "d", "e"] }, {     "time": "12:00",     "day": "day 1",     "name": "intermission a",     "category": ["a", "b", "c", "d"] }, {     "time": "13:00",     "day": "day 1",     "name": "session four",     "category": ["h", "a", "e"] }, {     "time": "9:00",     "day": "day 2",     "name": "session five",     "category": ["d", "e", "b", "g"] }, {     "time": "11:00",     "day": "day 2",     "name": "session six",     "category": ["a", "e", "c"] }, {     "time": "12:00",     "day": "day 2",     "name": "session seven",     "category": ["g", "h", "b", "c"] }] 

html

<li ng-repeat="cat in categoryarray">     <label>     <input type="checkbox" ng-model="cat.on" ng-change="checkchange()" />{{cat.name}}</label> </li> <hr> <h1><strong>category:</strong></h1>  <div ng-repeat="sessionitem in sessionarray | filter:myfunc | orderby: 'id'" class="ng-scope">     <h3>{{sessionitem.name}}</h3> </div>     

demo

to nest filter add pipe | , use "filter" filter normally.

<div ng-repeat="sessionitem in sessionarray | filter:myfunc | filter:thefilter | orderby: 'id'"> 

check example here.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -