[英]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.