简体   繁体   English

Javascript或D3js表示法

[英]Javascript or D3js Notation

How is there an assignment operator in the OR function. OR函数中如何有赋值运算符。

What would be the result of each of the two return statements. 这两个return语句中的每一个的结果将是什么。

Refer: http://www.d3noob.org/2014/01/tree-diagrams-in-d3js_11.html 请参阅: 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; })

in your example, usually it is the way used to define unique index in d3 在您的示例中,通常这是在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

second is same: 第二个是相同的:

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

(For reference: "Truthy" and "Falsy" Values ) (供参考: “ Truthy”和“ Falsy”值

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

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