gpt4 book ai didi

JavaScript 或 D3js 表示法

转载 作者:行者123 更新时间:2023-12-03 11:26:54 25 4
gpt4 key购买 nike

OR函数中怎么会有赋值运算符。

两个 return 语句各自的结果是什么。

引用:http://www.d3noob.org/2014/01/tree-diagrams-in-d3js_11.html

var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });

nodeEnter.append("text")
.attr("x", function(d) {
return d.children || d._children ? -13 : 13; })

最佳答案

在您的示例中,通常是在 d3 中定义唯一索引的方式

var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
//here if d.id exists and is truthy, just return d.id; if not, then assign d.id to ++i

第二个是相同的:

if d.children is (defined and truthy value) then return -13
if d.children is not defined or is falsy then return 13

(引用:"Truthy" and "Falsy" Values)

关于JavaScript 或 D3js 表示法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26881240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com