简体   繁体   English

selection.exit()。remove()方法不会覆盖或删除

[英]selection.exit().remove() method does not do overwriting or deletion

I have a problem with updating existing layout data. 我在更新现有布局数据时遇到问题。

I have nodes, where every node consists of group with circle and foreignObject nested. 我有节点,每个节点都由嵌套有circle和foreignObject的组组成。 After nodes data update, content of each node (circle and foreignObject) is added one more time to group element. 节点数据更新后,每个节点(圆形和外来对象)的内容又添加了一次到组元素。

I am pretty sure that problem is somewhere between enter().data() and exit().remove() methods. 我很确定问题出在enter().data()exit().remove()方法之间。

My code: 我的代码:

var node = mainSvg.select('.nodes').selectAll('.node')
    .data(nodes, function(d) {
        return d.id
    });

node.enter().append('g');

var circle = node.append('circle');
var foreignObject = node.append('foreignObject');

node.exit().remove();

I dropped out needles code, so it could be as cleaner as it can. 我删除了针代码,所以它可能会更干净。

I am still not sure what exactly is there behind exit and enter methods, but I solved the problem. 我仍然不确定exit和enter方法后面到底有什么,但是我解决了这个问题。

Old code 旧代码

var node = mainSvg.select('.nodes').selectAll('.node')
    .data(nodes, function(d) {
        return d.id
    });

node.enter().append('g');

var circle = node.append('circle');
var foreignObject = node.append('foreignObject');

node.exit().remove();

New code 新密码

var node = mainSvg.select('.nodes').selectAll('.node')
    .data(nodes, function(d) {
        return d.id
    }).enter().append('g');

var circle = node.append('circle');
var foreignObject = node.append('foreignObject');

mainSvg.select('.nodes').selectAll('.node')
    .data(nodes, function(d) {
        return d.id
    }).exit().remove();

And it works fine. 而且效果很好。 Thanks to @LarsKothoff for patience and will to help. 感谢@LarsKothoff的耐心和帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM