I'm currently delving into the realm of D3 visualization and I have a feeling that there might be a solution out there for what I'm attempting to achieve.
Let's assume I have JSON data structured like this:
var arr = [
{
"name":"John",
"maxAge": 35,
"info":[
{
"age":31,
"height":6,
"weight":155,
"eyes":"green"
},
{
"age":35,
"height":6,
"weight":165,
"eyes":"green"
}
]
},
{
"name":"Eric",
"maxAge":30,
"info":[
{
"age":29,
"height":5,
"weight":135,
"eyes":"brown"
},
{
"age":30,
"height":5,
"weight":155,
"eyes":"brown"
}
]
}
]
Imagine I'm iterating through the data using something akin to the following:
var outerDiv = d3.select("body")
.selectAll("div")
.data(arr)
.enter()
.append("div")
.attr("class","outerDiv");
to create outer divs for John and Eric, followed by:
var innerDivs = outerDiv.selectAll("p")
.data((d) => arr.info)
.enter()
.append("p")
.html("Weight = " + info.weight)
.attr("class","outerDiv");
to iterate through each piece of 'info' and represent it visually. Nonetheless, my visualization calls for me to 1) access 'maxAge' while looping through the 'info' array and 2) access 'info[1].height' when within 'info[0]'. Can either of these scenarios be accomplished?