I have an array of objects like so:
var dataObj = [{stuff:"thing"}, {other:"something"}, {you:"get"}, {the:"idea"}];
And I'm attempting to append one div with the key in it as text per object:
myElement
.selectAll("div.myClass")
.data([dataObj])
.enter()
.append("div")
.attr('class', 'myClass')
.text(function(d, i) {
return Object.keys(d)[i];
});
But this creates only one div element inside myElement like so:
<div id='myElement'><div class='myClass'>stuff</div></div>
What am I missing?
I also tried
myElement
.selectAll("div.myClass")
.data(dataObj)
.enter()
.append("div")
.attr('class', 'myClass')
.text(function(d, i) {
console.log("This never shows");
return Object.keys(d)[0];
});
to no avail.