2015-07-20 47 views
1

我有兩個斷開的組件。其中一個是「控制面板」,點擊時,其中的每個節點都會根據邊緣的重量觸發某個事件,從而從另一個邊緣移除某些邊緣。使用eles.restore();恢復邊緣不工作 - 我的代碼有什麼問題?

cy.on('tap', 'node', function(evt){ 
    var node = evt.cyTarget; 
    var clicked_val = node.data('value'); 
    // What is the value of the clicked node in the "control" graph? 

    if (typeof(clicked_val) != "undefined"){ 
    // Only "control panel" graph nodes have 'value' 

    var to_restore = cy.edges("[weight > 0]"); 
    to_restore.restore(); 
    // Restore everything, then... 

    var to_remove = cy.edges("[weight < "+clicked_val+"]"); 
    cy.remove(to_remove); 
    // Remove edges whose weight is less than those you want. 
    } 
}); 

cy.edges("[weight > 0]");應該抓住每個邊沿(在非控制圖),並且在一些測試似乎確實。然而,to_restore.restore();並沒有把他們全部帶回來。

所有邊都有唯一的ID,這應該不成問題。

任何想法讚賞。我沒有使用restore();是否正確?

回答

0

您正在查詢圖形,然後調用該查詢結果中元素的恢復。這意味着你在圖中已經存在的元素上調用restore() - 沒有任何效果。保持參考刪除元素正確使用restore()

+0

謝謝!我想這樣做的麻煩在於,如果ID中的任何一個都與圖中的事物相匹配,則不會恢復任何內容。 – onbooze