I have a JSON file called datas that contains the following information:
[
{"value": "1", "text": "aaa"},
{"value": "2", "text": "bbb"},
{"value": "3", "text": "ccc"},
{"value": "4", "text": "ddd"},
{"value": "5", "text": "eee"},
{"value": "6", "text": "fff"},
{"value": "7", "text": "ggg"},
{"value": "8", "text": "hhh"},
{"value": "9", "text": "iii"},
{"value": "10", "text": "jjj"}
]
My goal is to filter data from this JSON file based on an array of "b" values (b0, b1, b3, etc).
$scope.array = {"badge":"1,2,5,7","id":"0","b0":"1","b1":"2","b2":"5","b3":"7"}
For example:
Given an array with b0, b1, b2 and b3 containing the values 1, 2, 5, and 7, I want to retrieve only those specific values from the datas JSON file and display their corresponding text values.
The format of the array may vary, so I need to account for parameters in the form of b+"number".
Here are a few examples:
$scope.array = {"badge":"1,2,3,9","id":"0","b0":"1","b1":"2","b2":"3","b3":"9"}
$scope.array = {"badge":"1,2,7","id":"0","b0":"1","b1":"2","b2":"7"}
$scope.array = {"badge":"1,2,5,7,8,9","id":"0","b0":"1","b1":"2","b2":"5","b3":"7","b4":"8","b5":"9"}
To access the JSON file using AngularJS, I use the following code:
$http.get("/json/datas.json").success(function(data) {
$scope.datas= data;
});
The values are displayed using ng-repeat.
<div ng-repeat="data in datas">
<span ng-bind-html="data.text"></span>
</div>
Only the HTML body is displayed:
aaa bbb eee ggg