使用d3.js,如何选择特定<;g>;在<;文本>;作为它的孩子?

使用d3.js,如何选择特定<;g>;在<;文本>;作为它的孩子?,d3.js,D3.js,初始html如下所示 <svg> <g> <rect></rect> <text>selectThis</text> </g> <g> <rect></rect> <text>dont_selectThis</text> </g> 选择这个 别选这个 我必须选择g标记,它有子文本标记和它的值“sele

初始html如下所示

<svg>
<g>
    <rect></rect>
    <text>selectThis</text>
</g>

<g>
    <rect></rect>
    <text>dont_selectThis</text>
</g>

选择这个
别选这个

我必须选择g标记,它有子文本标记和它的值“selectThis”,并且应该向它附加一些其他文本标记,这样最终的输出将是

<svg>
<g>
    <rect></rect>
    <text>selectThis</text>
    <text> extra added </text>
</g>

<g>
    <rect></rect>
    <text>dont_selectThis</text>
</g>

选择这个
额外增加
别选这个

您可以通过过滤初始选择来完成此操作:

d3.selectAll("g")
  .filter(function() {
    return d3.select(this).select("text").text() == "selectThis";
  });