I did not get the exact answer I needed to fix the issue I am seeing. I have a JSON object like below,
{
"id":1,
"time":"2018-04-15 22:04:21",
"alert":{
"id":6,
"name":"Alert Test 416"
},
"source":{
"type":"Service",
"id":37379,
"name":"489-127-2367"
},
"value":1310384.000000 }, {
"id":1,
"time":"2018-04-15 22:04:21",
"alert":{
"id":6,
"name":"Alert Test 416"
},
"source":{
"type":"Service",
"id":37826,
"name":"489-332-4137"
},
"value":1352071.000000 }, {
"id":2,
"time":"2018-04-16 22:04:36",
"alert":{
"id":6,
"name":"Alert Test 416"
},
"source":{
"type":"Service",
"id":37364,
"name":"489-776-9604"
},
"value":6021.000000 }
There are two entries with id = 1 and one entry with id = 2. I would like to see an output like below,
<tbody>
<tr id="1" role="row">
<td>2018-04-15 22:04:21</td><td>Alert Test 416</td><td>Service</td><td>489-127-2367</td></tr>
<tr id="1" role="row">
<td>2018-04-15 22:04:21</td><td>Alert Test 416</td><td>Service</td><td>489-332-4137</td></tr>
<tr id="2" role="row">
<td>2018-04-16 22:04:36</td><td>Alert Test 416</td><td>Service</td><td>489-776-9604</td></tr>
</tbody>
But I get an output like below instead,
<tbody>
<tr id="1" role="row">
<td>2018-04-15 22:04:21</td><td>Alert Test 416</td><td>Service</td><td>489-127-2367</td></tr>
<tr id="2" role="row">
<td>2018-04-16 22:04:36</td><td>Alert Test 416</td><td>Service</td><td>489-776-9604</td></tr>
</tbody>
The code only takes the very first entry for each top level id and then moves to the next id.
Here is the code,
<tbody>
{history.map((item) => {
return <tr key={item.id} id={item.id} role='row'>
<td>{item.time}</td>
<td>{item.alert.name}</td>
<td>{item.source.type}</td>
<td>{item.source.name}</td>
</tr>
})}
</tbody>
The history is the object containing the JSON input shown above. How should the above be modified so that I get the desired result?