JSFiddle - React, Tailwind, and code Playground
CSS
pre {
display: block;
padding: 9.5px;
margin: 0 0 10px;
font-size: 13px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
}
JavaScript
var res = {
"Result": "success",
"Key": "12345",
"Data": [{
"ID": "GFDCV34",
"lastChangedDate": "2015-12-03 11:14:27"
}, {
"ID": "IDJHE23",
"lastChangedDate": "2015-12-03 15:17:47"
}, {
"ID": "KDJBD34",
"lastChangedDate": "2015-12-03 05:25:11"
}]
};
var i = 0;
function getdetails(id) {
i++;
return {
"Result": "success",
"Key": Math.round(Math.random() * 1000),
"Data": [{
"ID": id,
"name": "Name of event " + i,
"date": "date of event " + i,
"location": "location of event " + i,
"lastChangedDate": "2015-12-03 05:25:11"
}]
};
}
var tmp;
res.Data.map(function(val,i){
tmp = getdetails(val.ID);
console.log(tmp)
Object.keys(tmp.Data[0]).map(function(v,j){
val[v] = tmp.Data[0][v];
});
});
document.querySelectorAll("pre")[0].innerHTML = JSON.stringify(res);