javascript - Cytoscape 不恢复元素

标签 javascript cytoscape.js

根据文档 ( http://js.cytoscape.org/#eles.remove/http://js.cytoscape.org/#eles.restore ),可以使用 eles.restore() 方法从图表中恢复之前删除的元素。

但是我无法恢复此 facon 中的所有元素?

applyElementFilters = () => {
    const excluded = [1, 2, 3];

    // Restore all elements first, this apparently does nothing
    this.cy.elements().restore();

    if (excluded && excluded.length > 0) {
        const excludedElements = this.cy
            .elements()
            .filter(element => excluded.includes(element.data("id")));

        this.cy.remove(excludedElements);
    }
};

最佳答案

如文档中所述,您已保存已删除元素的引用以用于恢复它们。

// remove selected elements
var eles = cy.$(':selected').remove();

// ... then some time later put them back
eles.restore();

在您的情况下,当您通过执行此操作删除元素时

this.cy.elements().restore();

您可以将它们保存在变量或this中,如下所示

this.__removedElements = this.cy.elements().remove();
// or
var removedElements; // global variable
removedElements = this.cy.elements().remove();

然后你可以像下面一样恢复它们

this.__removedElements.restore()
// or
removedElements.restore() 

关于javascript - Cytoscape 不恢复元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647518/

相关文章:

javascript - 100px 后的 jQuery 滚动功能

javascript - 操作电子表格数据以实现可视化

java - 如何从 WebView 中获取文本

javascript - 带子数组的组数组

javascript - 如何在 Cytoscape JS 中的两个节点之间添加多个偏移边?

cytoscape.js - 计算机网络图混合布局的正确方法

javascript - 在 IE9 中不将任何内容从 Javascript 传递到 VBScript

javascript - 叶节点 cytoscape 的不同行为

javascript - 我如何自定义 cytoscape.js 中的边缘,以便线条为虚线和动画/闪烁?

cytoscape.js - 如何更改 cytoscape 节点的标签