2017-12-05 11 views
0

설명서 (http://js.cytoscape.org/#eles.remove/http://js.cytoscape.org/#eles.restore)에 따르면 eles.restore() 메서드를 사용하여 이전에 제거 된 요소를 그래프에서 복원 할 수 있습니다.요소를 복원하지 않는 Cytoscape

그러나이 사이트의 모든 요소를 ​​복원 할 수 없습니까?

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); 
    } 
}; 

답변

1

설명서에서 설명한대로 removed 참조를 저장하여 복원 할 수 있습니다. 이

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

을 수행하여 요소를 제거하고 당신이 당신이 그들을 복원 할 수 있습니다 다음

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

아래처럼 this에 변수에 저장하거나 할 수 있습니다 경우

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

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

아래처럼

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

Ah ha, 나는 단지 ": removed"선택자를 사용하여 찾을 수 있다고 확신했습니다. – janhartmann

+0

예상대로 작동하면 허용 표시를하십시오. :) –

+0

1 분 남음! ;-) – janhartmann