[英]Svg D3.js How to selectAll using condition
Assume that there are lots of group ( <g/>
) elements in the page body. 假设页面主体中有很多group( <g/>
)元素。 Some of these group elements have id, some of them not, however there is an interest only in those group elements which has an id
which begins with string foo
. 这些组元素中有一些具有id,但有些则没有,但是仅对那些以字符串foo
开头的id
组元素有兴趣。
How can you operate only on subset of selected elements? 如何仅对选定元素的子集进行操作?
There is a need of something like this: 需要这样的事情:
d3.selectAll("g").where(id like 'foo%')
[]选择属性,并且^ =表示开头,因此您最终以此...
d3.selectAll("g[id^=foo]")
除了使用选择器进行过滤之外,您还可以使用D3的.filter()
函数:
d3.selectAll("g").filter(function(d) { return this.id.match(/foo/).length > 0; });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.