[英]d3.select by namespaced attribute
This almost does it for my case: 对于我来说,这几乎可以做到:
d3.select('g[id^="layer"]')
But it's just not bulletproof. 但这不是防弹的。 I need to be able to do:
我需要能够:
d3.select('g[inkscape:groupmode="layer"]')
This produces an invalid selector error. 这将产生无效的选择器错误。 Doesn't make a difference whether I add
inkscape
to d3.namespaces
or not. 我是否将
inkscape
添加到d3.namespaces
没有关系。
Ps I'm working on an Inkscape edited SVG, I need to be able to render it in browser DOM, manipulate it and export it back to an SVG with all "metadata" in namespaced attributes intact. ps我正在使用Inkscape编辑的SVG,我需要能够在浏览器DOM中呈现它,对其进行操作,然后将其导出回SVG,并完整保留命名空间属性中的所有“元数据”。
I ended up filtering using Element.getAttributeNS . 我最终使用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'
})
Does anyone know of a more D3-like way of doing it? 有人知道更像D3的方式吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.