After receiving a JSON from an API, I store it in this.state.data
as shown below:
[
{
"name": "Primary Category",
"value": [
{
"value": "Fracture",
"Diagnosis_Code": ["DIAG003"],
"name": "Primary Category",
"FK_Diagnosis_Content_ID": 3,
"FK_Diagnosis_Category_ID": 1
},
{
"value": "Osteoarthritis",
"Diagnosis_Code": ["DIAG001"],
"name": "Primary Category",
"FK_Diagnosis_Content_ID": 1,
"FK_Diagnosis_Category_ID": 1
},
{
"value": "Osteonecrosis",
"Diagnosis_Code": ["DIAG002", "DIAG004"],
"name": "Primary Category",
"FK_Diagnosis_Content_ID": 2,
"FK_Diagnosis_Category_ID": 1
}
]
},
{
"name": "Anatomy",
"value": [
{
"value": "Hip",
"Diagnosis_Code": ["DIAG001"],
"name": "Anatomy",
"FK_Diagnosis_Content_ID": 4,
"FK_Diagnosis_Category_ID": 2
},
{
"value": "Pelvis",
"Diagnosis_Code": ["DIAG002", "DIAG003", "DIAG004"],
"name": "Anatomy",
"FK_Diagnosis_Content_ID": 6,
"FK_Diagnosis_Category_ID": 2
}
]
}
]
I am using a dynamic state handling function like the one below:
onChangeTextPress(key, value){
this.state.selected[key] = value
//another code
}
The example of this.state.selected
is
[ 'Primary Category': 'Fracture', Anatomy: 'Hip']
I want to extract the values of FK_Diagnosis_Content_ID
based on the keys and values stored in this.state.selected
.
For example, given the current content of selected
, the expected result would be: [3, 4]
This output is derived by matching the key-value pairs in the JSON data with the corresponding entries in the this.state.selected
object. In this case, it relates to the name
and value
fields.
If more clarification is needed, please feel free to ask any questions.
I appreciate any help or insights provided.