Cytoscape 不恢复元素
Cytoscape not restoring elements
根据文档 (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()
根据文档 (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()