How can I get access to the current selection inside a D3 callback?
group.selectAll('.text')
.data(data)
.enter()
.append('text')
.text((d) => d)
.attr('class', 'tick')
.attr('y', (d) => {
// console.log(this) <-- this gives me window :( but I want the current selection or node: <text>
return d
})
I could do a d3.select('.tick')
in the callback, since by then I've added a class and can get the node via d3.select, but what if I didn't add the class?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…