根据文档(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);
}
};
如文档中所述,您已保存removed
用于恢复元素的参考。
// 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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句