Angularjs filter - Compare multiple checkboxes boolean with JSON list, display union -
in view there 3 checkboxes change states of 3 values of $scope.colorchoice.
i write function compares every true color corresponding color in json list. if person has @ least 1 color in array has been checked true, persons name should displayed.
how can write such function?
so far i've come far:
json list:
[ { "name": "kevin", "colors": ["red, green"] }, { "name": "hans", "colors": ["green"] }, { "name": "jolene", "colors": ["red, blue"] }, { "name": "peter", "colors": ["blue"] } ]
checkboxes:
<label ng-repeat="(item,enabled) in colorchoice"> <input type="checkbox" ng-model="colorchoice[item]"> </label>
controller:
$scope.colorchoice = { red: false, green: false, blue: false };
for example:
$scope.colorchoice = { red: true, green: false, blue: true };
...would display: kevin, jolene, peter
thanks help!
vin
one thing might want angular-checklist-model,
http://vitalets.github.io/checklist-model/
that won't solve problem see handling handle you. find clean use purpose yours though.
with colorchoice object whether use angular-checklist-model or not though:
html
<ul> <li ng-repeat='person in people | filter: colorfilter'>{{person.name}}</li> </ul>
controller filter function
$scope.colorfilter = function(person) { (var = 0; < person.colors.length; i++) { var color = person.colors[i]; if ($scope.colorchoice[color] == true) return true; } return false; };
i use angular filters functions return true or false. can extremely versatile situations this. angular filter guide