I have been working on filtering out JSON data using AngularJS. Here is my approach:
angular.module('staticSelect', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.data = {
multipleSelect: ["classA"]
};
$scope.isoffice = function(apps) {
return apps.type === $scope.data.multipleSelect[0];
};
console.log($scope.data.multipleSelect[0]);
$scope.apps = [{
"id": "1",
"type": "classA",
"name": "Name 1"
}, {
"id": "2",
"type": "classB",
"name": "Name 2"
}, {
"id": "3",
"type": "classC",
"name": "Name 3"
}, {
"id": "4",
"type": "classD",
"name": "Name 4"
}, {
"id": "5",
"type": "classE",
"name": "Name 5"
}
];
}]);
This method works well when the user selects only one value from the list and "type" is not an array. However, I am now exploring how to filter data in a scenario where users can select multiple values from a list, with data being filtered using the OR condition.
$scope.apps = [{
"id": "1",
"type": ["classA","classB","classC"],
"name": "Name 1"
}, {
"id": "2",
"type": ["classB","classC","classE"],
"name": "Name 2"
}, {
"id": "3",
"type": ["classC"],
"name": "Name 3"
}, {
"id": "4",
"type": ["classD","classC"],
"name": "Name 4"
}, {
"id": "5",
"type": ["classA","classB","classC","classD","classE"],
"name": "Name 5"
}
];
For example, if a user selects class A and Class B, the output should be Name 1, Name 2, Name 5