这是网球抽签,我需要能够再见,所以大多数父母都有两个孩子,即。每场比赛的获胜者都会通过,但在某些情况下会轮空,因此只有一个孩子。请参阅此处作为示例,其中一些父匹配项没有子项,而有些匹配项有一个:http ://www.irtpa.com/index.php/realtennis/ladder/1246
我认为这个答案没有帮助:How to remove node on tree layout D3.js?
因为它假设节点的所有子节点都被隐藏/删除。
根据上面的stackoverflow答案,我已经走了这么远,但我的大脑看不到删除/隐藏孩子的解决方案:
function check_children(data, parent) {
// recurse through array and toggle/hide any Match Byes
if (typeof data.data != "undefined") {
if (data.data.bye == "byeM") {
toggle(parent);
}
}
if (data.children) {
check_children(data.children[0], data);
check_children(data.children[1], data);
}
}
function toggle(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
}