我正在制作D3树布局.我看了一遍,当你没有数据绑定到DOM并且你试图删除它时,似乎会出现此错误.我不仅确保那里有数据,而且还通过在修改之前和之后对链接数组进行计数来确保数据发生变化.
这是我的更新功能的问题代码.
link = linkElements.selectAll("path.link") //link elements is dom object that holds my links
.data(links).enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
link.exit().remove();
Run Code Online (Sandbox Code Playgroud)
它与许多例子几乎相同,但我一直看到这个:
TypeError: link.exit is not a function
link.exit().remove();
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?我做了类似节点的事情.我无法从树中删除任何内容.
mee*_*mit 10
注意link分配到的内容:
link = linkElements.selectAll("path.link")
.data(links)
.enter() // <----- THIS
.append("path")
.attr("class", "link")
.attr("d", diagonal);
Run Code Online (Sandbox Code Playgroud)
因此,link包含由enter()子选择产生的新附加节点的选择,因此exit()根据定义它没有子选择.
你需要什么(大概意思)做的就是分配link到整个数据绑定选择,以及随后的子选项的工作:
link = linkElements.selectAll("path.link")
.data(links);// link assigned
link.enter() // <----- THIS
.append("path")
.attr("class", "link")
.attr("d", diagonal);
link.exit().remove(); // no more errors!
Run Code Online (Sandbox Code Playgroud)