且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

D3-显示/隐藏仅单击的节点的文本

更新时间:2023-11-23 23:48:40

node是包含所有组的选择(我想它们是组,因为您没有复制/粘贴整个选择).

node is a selection containing all your groups (I suppose they are groups, since you didn't copy/paste the entire selection).

如果只想在被单击的组中执行任何操作,则必须使用d3.select(this)进行选择,该操作将选择当前(在您的情况下为被单击的)DOM元素.

If you want to do anything only in the clicked group, you have to select it using d3.select(this), which selects the current (in your case, the clicked) DOM element.

因此,而不是:

node.select("text")

应该是:

d3.select(this).select("text")