我试图根据ID为力定向图中的各种元素进行选择。我可以选择一个节点,它的标签基于他们的ID没有问题,但当我试图选择一个链接时,它只返回空值,就像这样-(在*)
ut {_groups: Array(1), _parents: Array(1)}
_groups: Array(1)
0: Array(1)
****0: null****
length: 1
__proto__: Array(0)
length: 1
__proto__: Array(0)
_parents: [html]
__proto__: Object
d3.select("#P DataIns")
如果我检查P数据和Ins之间的链接,它会显示
<line id="P DataIns"></line>
var childNode = d3.select("#" + checkingNode.id);
childNode.style("opacity", 1);
childNode.style("stroke", highlight_color);
var childLink = d3.select("#" + node2.id + checkingNode.id);
childLink.style("opacity", 1);
childLink.style("stroke", highlight_color);
var childLabel = d3.select("#" + checkingNode.id + "label");
childLabel.style("opacity", 1);
childLabel.style("font-weight", "bold");
这是我用于选择的代码,只有用于选择子链接的中间代码不起作用。这一个和另外两个有什么不同的地方我做错了吗?所有ID仅使用字母或空格。链接创建如下,以供参考-
link = link.data(config.links, d => d.id);
link.exit().remove();
link = link.enter().append("line")
.attr("id", function (d) {
return d.source + d.target;
})
.attr("class", "link")
.attr("stroke-width", 2)
.attr("stroke", "#888")
.merge(link);
我复习过了
Mike Bostocks article
对于如何选择工作,我觉得这应该是工作。。。