[英]d3.select by namespaced attribute
对于我来说,这几乎可以做到:
d3.select('g[id^="layer"]')
但这不是防弹的。 我需要能够:
d3.select('g[inkscape:groupmode="layer"]')
这将产生无效的选择器错误。 我是否将inkscape
添加到d3.namespaces
没有关系。
ps我正在使用Inkscape编辑的SVG,我需要能够在浏览器DOM中呈现它,对其进行操作,然后将其导出回SVG,并完整保留命名空间属性中的所有“元数据”。
我最终使用Element.getAttributeNS进行过滤。
// Set namespace
d3.namespaces.inkscape = 'http://www.inkscape.org/namespaces/inkscape'
// Filter selection
d3.select('#my_svg').selectAll('g').filter(function (d, i) {
return this.getAttributeNS(d3.namespaces.inkscape, 'groupmode') === 'layer'
})
有人知道更像D3的方式吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.