admin管理员组文章数量:1320661
I'm making a D3 tree layout. I've looked all over and it seems like this error shows up when you don't have data tied to the DOM and you try to remove it. I've ensured not only that there is data there, but I've also made sure the data changes by doing a count on the links array before and after I modify it.
Here is the problem code from my update function.
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();
It's practically the same as many examples, but I keep seeing this:
TypeError: link.exit is not a function
link.exit().remove();
What is going on? I do something similar with the nodes. I can't get anything to delete from the tree.
I'm making a D3 tree layout. I've looked all over and it seems like this error shows up when you don't have data tied to the DOM and you try to remove it. I've ensured not only that there is data there, but I've also made sure the data changes by doing a count on the links array before and after I modify it.
Here is the problem code from my update function.
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();
It's practically the same as many examples, but I keep seeing this:
TypeError: link.exit is not a function
link.exit().remove();
What is going on? I do something similar with the nodes. I can't get anything to delete from the tree.
Share Improve this question asked Dec 22, 2014 at 5:13 Joshua HedgesJoshua Hedges 3174 silver badges16 bronze badges1 Answer
Reset to default 11Notice what link
is getting assigned to:
link = linkElements.selectAll("path.link")
.data(links)
.enter() // <----- THIS
.append("path")
.attr("class", "link")
.attr("d", diagonal);
So link
is a selection containing newly appended nodes resulting from the enter()
sub-selection, so it doesn't have an exit()
sub-selection by definition.
What you need (and probably meant) to do is assign link
to the entire data-bound selection, and then work on the sub-selections:
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!
版权声明:本文标题:javascript - D3 TypeError: link.exit is not a function link.exit().remove(); What am I doing wrong? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742064038a2418725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论