gpt4 book ai didi

javascript - 在 Node Tap Cytoscape 上隐藏和显示子节点

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:13 24 4
gpt4 key购买 nike

我正在尝试使用广度优先布局在 Cytoscape 中创建一个可折叠的树结构,以复制 D3 collapsible tree .

我试图在节点上复制这种类型的点击操作,但另外添加恢复功能 - Images & breadthfirst layout

我选择 Cytoscape 的原因是因为我有一个场景,其中树的节点超过 1 个父节点。

我尝试使用以下代码添加点击事件:

cy.on('tap', 'node', function() {
if (this.scratch().restData == null) {
// Save node data and remove
this.scratch({
restData: this.connectedEdges().targets().remove()
});
} else {
// Restore the removed nodes from saved data
this.scratch().restData.restore();
this.scratch({
restData: null
});
}
}

但是,这仅能成功折叠和展开其直接子节点(其余节点仍然可见),并且在我点击叶节点时也会导致问题。

如果有人知道展开和折叠节点的方法,请帮忙。

编辑:伙计们,如果有人也知道简单多级树的解决方案,那也是一个好的开始...

最佳答案

我替换了这行代码:

 restData: this.connectedEdges().targets().remove()

用这个:

restData: this.successors().targets().remove()

并且此代码现在折叠子节点和孙节点(仅在 3 个级别上测试)并且叶节点在单击时不再折叠到其父节点中。

关于javascript - 在 Node Tap Cytoscape 上隐藏和显示子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41506664/

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