.point-create 为点
.tipArrow-create为箭头
`showTipArrow=()=>{
d3.selectAll('.point-create').on('click',function(){//选择所有的点添加点击事件
let $thisDom=d3.select(this);
d3.selectAll('.tipArrow-create').filter(function(d,i,list){
let arrowDom=d3.select(this);
if(arrowDom.attr('regId')==$thisDom.attr('regId')){//匹配点是否跟箭头的regId一致
arrowDom.attr('display','');
}
});
});
}`
点是动态添加的,showTipArrow函数位置放在动态添加点函数里面,
d3.select('#points').append('use')
.attr('id', 'red_'+thisId)
.attr('regId',thisId)
.attr('type', 'point')
.attr('x', width-10)
.attr('y', cyRed-10)
.attr('yy',cyRed)
.attr('class', 'point-create')
.attr('xlink:href','#point')
.call(d3.drag()
.on('start', dragstarted)
.on('drag', dragged)
.on('end', dragended));
this.showTipArrow();
结果就是需要点击2次的时候添加的click函数才会生效,有人知道怎么回事吗?
我把添加的drag事件去掉以后就正常了?