答案 0 :(得分:2)
您可以使用subselection:
执行此操作// keep reference to appended text elements
var someText = nodeEnter.append("text")
.attr("class", "properties")
.attr("text-anchor", "middle")
.attr("y", 52)
.style("fill-opacity", 1);
// sub-select them with properties array
someText.selectAll('tspan')
.data(function(d) {
return d.properties || []; // catch situation where child has no properties
})
.enter()
.append('tspan')
.attr("x", 0)
.attr('dy', "0.9em")
.text(function(d) {
return d;
});
更新了fiddle。