I need assistance with setting up a JSON object for a post in Angular2/Typescript. I am trying to dynamically set the nested object values for a key. Is it possible to achieve this using Angular2/Typescript?
I have attempted to retrieve the values from JSON and dynamically set them using a repetitive function call. I believe recursion may be the solution. Can someone guide me on how to implement recursion for this function?
let encounterPayLoad = {
patient:this.orderEncounter.patient.uuid,
visit:this.orderEncounter.visit.uuid,
encounterType:this.orderEncounter.encounterType.uuid,
obs:[
{
groupMembers:[
{
concept:val,//setting concept values as dynamically
value:"1000"
},
}
],
orders:[
],
encounterProviders:[
{
provider: this.appConstants.defaultProviderUUID,
encounterRole: this.appConstants.defaultEncounterRoleUUID
}
]
}
this.groupMember.push(encounterPayLoad);
console.log("@payLoad",this.groupMember);
}
I am aiming for the final object structure as shown below. Currently, it only works at one level inside groupMembers.
{
"patient":"e56faafe-70e2-422d-a260-a1c69e72a54c",
"visit":"7848a99a-323b-4873-9711-2b5f27be86f9",
"encounterType":"7c179057-ae3d-44d8-b9e7-f5e514992f41",
"obs":[
{
"groupMembers":[
{
"concept":"4876e25c-f580-4a84-9357-a283de220b44",
"value":"1000"
},
{
"concept":"964f1f1e-7c26-4e59-bb23-692a4ae02c6f",
"value":"2000"
},
{
"concept":"02f962f7-c864-474e-a63a-56feed2ad2dc",
"value":"3000"
}
],
"concept":"745449b2-c0e6-4f23-8428-942499142533",
"order":"0472a6fe-63c5-40f9-b761-dbfa6f91e117"
}
],
"orders":[
],
"encounterProviders":[
{
"provider":"f9badd80-ab76-11e2-9e96-0800200c9a66",
"encounterRole":"240b26f9-dd88-4172-823d-4a8bfeb7841f"
}
]
}