首页 > 解决方案 > d3 相当于 jQuery find("*")

问题描述

我目前使用 jQuerys 的 find('*').method 来获取 svg 元素的所有子元素:

$(svg).find("*").each(function(){
  //do s.th.
});

我想与 d3 相同,我尝试过:

d3.select(svg).selectAll().each(function() {
  //do s.th.
});

d3.select(svg).selectAll().size()

尽管 SVG 有多个子元素,但始终返回 1。我究竟做错了什么?

如果 ypu 想查看此问题适用于何处或需要示例:SVG to Image export performance issues (using canvg / XMLSerializer / getComputedStyle)

标签: jqueryd3.js

解决方案


d3.select(svg).selectAll("*")

做到了。多亏了高积云,我可以发誓我已经测试过了……还是谢谢你


推荐阅读