I am trying to render some html elements based on JSON data. I have a React class which takes these objects and produces a string list of divs; the values in the divs correspond to the first value in each object in the JSON.
This is my JSON:
{"spaces":{
"space1": {
"0": 1.0,
"1": 2.0,
"2": 0.0,
}
"space2": {
"0": 0.0,
"1": 2.0,
"2": 0.0,
}
"space3": {
"0": 0.0,
"1": 2.0,
"2": 0.0,
}
and this is the class, which gets the JSON:
import React, { Component } from "react";
import "./Maps.css";
import df3 from "./data/df3.json"
import sample from "./data/sample.json"
class Maps extends Component {
constructor() {
super();
const data = df3;
this.state = data
}
render()
{
console.log(this.state)
var df4 = df3["Spaces"]
var d1 = '';
for (var key in df4)
{
var host = df4[key];
d1 += '<div class="'+key+'" value="'+host[0]+'"/>';
}
console.log(d1)
return (
<div id="Maps">
</div>
)
}
}
export default Maps
This is what the class outputs, a string wrapping a bunch of divs:
<div class="space1" value="1"/><div class="space2" value="0"/><div class="space3" value="0"/>
I would like to actually have these divs returned on the screen:
return (
<div id="Maps">
// the list of divs should be returned
</div>
)
Any help, as always, is appreciated.