【发布时间】:2017-05-30 15:15:23
【问题描述】:
我是 D3.js 的新手,我想构建一个实时协作黑板。一个管理员客户端在 svg 上绘制路径,其他客户端接收它们。我正在尝试从客户端选择最后一个路径元素。在过去的几个小时里,我四处走动,找到了几个 How can I select :last-child in d3.js? 的帖子,但无法让它发挥作用。当我问:
console.log('svg ='+svg.selectAll("path")
我画了两条路径
svg ={"_groups":[{"0":{},"1":{}}],"_parents":[{"__on":[{"type":"click","name":"","capture":false},{"type":"mousedown","name":"drag","capture":false},{"type":"touchstart","name":"drag","capture":false},{"type":"touchmove","name":"drag","capture":false},{"type":"touchend","name":"drag","capture":false},{"type":"touchcancel","name":"drag","capture":false}]}]}
编辑:我的 DOM 结构
<svg id="myCanvas" width="960" height="500">
<rect fill="#F2EDE4" width="100%" height="100%"></rect>
<path fill="none" stroke="black" stroke-width="2" stroke-linejoin="round" stroke-linecap="round" d="M223.64999389648438,304.25L223.98332722981772,304.5833333333333C224.31666056315103,304.9166666666667,224.98332722981772,305.5833333333333,226.31666056315103,306.75C227.64999389648438,307.9166666666667,229.64999389648438,309.5833333333333,231.14999389648438,310.4166666666667C232.64999389648438,311.25,233.64999389648438,311.25,234.98332722981772,310.4166666666667C236.31666056315103,309.5833333333333,237.98332722981772,307.9166666666667,238.81666056315103,307.0833333333333L239.64999389648438,306.25"></path><path></path></svg>
提前致谢
【问题讨论】:
标签: d3.js