JSON Data Example
{
"rootData": {
"test1": {
"testData0": "Previous information",
"testData1": "Earlier Information"
},
"test2": {
"testData0": "Partial details",
"testData1": "Service details"
},
"test3": {
"testData0": "Regular content",
"testData1": {
"testData0": "Your customized package"
}
}
}
}
Component Script
import * as myData from './myData.json';
getData(dataValue: string){
console.log(myData.rootData.test1.testData0); //outputs "Previous Information.
return myData.rootData.{{data}}.testData0;
}
The getData method is used repeatedly within a loop with different values like 'test1', 'test2', and 'test3' being passed.
An ideal approach would be to dynamically retrieve data based on the provided key.
Currently, the attempt to use {{data}} is not valid in the JSON object.
The objective is to fetch specific data nested inside the JSON file by utilizing the string value passed to the function.
An alternative solution needs to be explored for achieving the intended functionality.