node.links()函數返回到節點對象的子節點的鏈接的數組,每個鏈接對象都有一個源和一個目標字段,其中包含對子節點的引用。
用法:
node.links();
參數:此方法不接受任何參數。
返回值:這個方法返回指向節點對象的子代的鏈接的數組。
範例1:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src=
"https://d3js.org/d3.v5.min.js">
</script>
</head>
<body>
<script>
var data = {
"name":"GeeksforGeeks",
"about":"Computer Science Portal",
"children":[
{"name":"GFG1"},
{"name":"GFG2"},
{"name":"GFG3"}
]
}
var root = d3.hierarchy(data);
a=root.links();
console.log(a);
for (i=0;i<a.length;i++){
console.log(a[i].source.children)
}
</script>
</body>
</html>
輸出:
範例2:不包含任何子項的根返回空鏈接數組。
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src=
"https://d3js.org/d3.v5.min.js">
</script>
</head>
<body>
<script>
var data = {"name":"GFG1"}
var root = d3.hierarchy(data);
console.log(root.links());
</script>
</body>
</html>
輸出:
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
- PHP Ds\Deque pop()用法及代碼示例
注:本文由純淨天空篩選整理自taran910大神的英文原創作品 D3.js node.links() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。