d3.select ...相当于jQuery.children() [英] A d3.select... equivalent to jQuery.children()

查看:411
本文介绍了d3.select ...相当于jQuery.children()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用d3在enter()上附加一些元素,然后更新它们。但是,下一次我尝试选择那些元素的选择比原来大得多。这是因为原始选择元素现在具有相同类型的子元素。 < g> < svg> 。我期望selectAll()只在第一个下降级别工作像jQuery.children()在d3有一个等价?如果不是最有效的方式来填补这个?

I'm using d3 to append some elements on enter() and then update them later. However, the next time i try to select those elements the selection is much larger than the original. This is because the original selection elements now have children that are the same type e.g.; <g>, <svg>. I expected selectAll() to only work at the first decedent level like jQuery.children() is there an equivalent in d3? If not whats the most efficient way to shim that?

推荐答案

没有等价于 jQuery.children )。这通常通过为你想一起选择的元素分配一个区别类来处理。

There's no equivalent to jQuery.children(). This is usually handled by assigning a distinguishing class to the elements you want to select together, e.g. something like this.

svg.selectAll("g").data(data)
   .enter()
   .append("g")
   .attr("class", "parent")
   .append("g")
   .attr("class", "child");

svg.selectAll("g"); // all g elements
svg.selectAll("g.parent"); // only parents
svg.selectAll("g.child"); // only children

这篇关于d3.select ...相当于jQuery.children()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆