I have this json file that I am appending to the html.
"{\"Item1\":[{\"Id\":2,\"Title\":\"Support\",\"Items\":8},{\"Id\":5,\"Title\":\"Datacenter\",\"Items\":5},{\"Id\":3,\"Title\":\"Bogholderiet\",\"Items\":5},{\"Id\":8,\"Title\":\"Helpdesk\",\"Items\":4},{\"Id\":9,\"Title\":\"SLA og VIP\",\"Items\":1},{\"Id\":7,\"Title\":\"Hostmaster\",\"Items\":1}],\"Item2\":[{\"Id\":7,\"FullName\":\"p11\",\"Items\":5},{\"Id\":17,\"FullName\":\"p8\",\"Items\":3},{\"Id\":9,\"FullName\":\"p10\",\"Items\":3},{\"Id\":8,\"FullName\":\"p6\",\"Items\":3},{\"Id\":3,\"FullName\":\"p1\",\"Items\":3},{\"Id\":5,\"FullName\":\"p2\",\"Items\":2},{\"Id\":16,\"FullName\":\"p3\",\"Items\":1},{\"Id\":11,\"FullName\":\"p4\",\"Items\":1}]}"
My question is how can I append only the value of "SLA og VIP". Below code I am able to access to array of Item1 and appending it to html.
if (key === 'Item1') {
value[key].forEach(function (val) {
var tbl3Row = "<tr " + (parseInt(val.TotalUnresolvedItems) > 3 ? " class='colorgul'" : "") + (parseInt(val.TotalUnresolvedItems) < 4 ? " class='colorgreen'" : "") + ">" + "<td>" + val.Title + "</td>" + "<td>" + val.TotalUnresolvedItems + "</td>" + "</tr>"
table3Rows += tbl3Row;
})
}
But now I am only trying to access to the Title value"SLA og VIP". This is the formula that i manage to find:
parsedData.Item1[4]
I just dont know how can I use this inside of this code:
if (key === 'Item1') {
value[key].forEach(function (val) {
var tbl3Row = "<tr " + (parseInt(val.TotalUnresolvedItems) > 3 ? " class='colorgul'" : "") + (parseInt(val.TotalUnresolvedItems) < 4 ? " class='colorgreen'" : "") + ">" + "<td>" + val.Title + "</td>" + "<td>" + val.TotalUnresolvedItems + "</td>" + "</tr>"
table3Rows += tbl3Row;
})
}
JSON.parse(string).Item1.find(x=>x.Id === 9).TitleId,TitleorFullnameandItemsproperties. What are you calling thevalue of "SLA og VIP"? What are the conditions on which you want to return something? You could use theid===9and having aTitleproperty. Is this the only possible JSON or are there any cases? What's the logic behind it?