For instance, here is a snippet of code that utilizes a JSON object:
"food": {
"appetizers": [
{
"id": 1,
"image": "../image/calammari.png",
"title": "rings",
"price": 11500,
"ingredient":[{
"id" : "0001",
"name": "avocado"
},
{
"id" : "0001",
"name": "tomato"
}
]
},
{
"id": 2,
"image": "../image/food2.png",
"title": "bang bang",
"price": 10000,
"ingredient":[{
"id" : "0001",
"name": "eggplant"
},
{
"id" : "0001",
"name": "cucumber"
}
]
}
In this scenario, if the element accessed equals 'tomato', only the food items containing tomato should be displayed.
Here is an example in HTML:
<div ng-repeat="appetizer in appetizers ">
<div>
<img ng-src="{{appetizer.image}}" />
<div >
<p >
{{appetizer.title | uppercase}}
</p>
</div>
Additionally, the following JavaScript logic is used:
var myAccess = ["tomato"];
$scope.test = [];
var appetizer = $scope.appetizers;
for (var i = 0; i < $scope.appetizers.length; i++) {
for (var j = 0; j < $scope.appetizers[i].ingredient.length; j++) {
if ($scope.appetizers[i].ingredient[j].name === myAccess) {
// Insert appropriate action here
}
}
}
return null; }
If anyone can provide assistance, it would be greatly appreciated!
In summary, when myAccess is set to 'tomato', the script should identify and extract the first appetizer with tomato as an ingredient, pushing only those ingredients with tomato.