使用eles.restore();恢复边缘不工作 - 我的代码出了什么问题?

时间:2015-07-20 10:35:57

标签: javascript restore cytoscape.js

我有两个断开连接的组件。其中一个是“控制面板”,其中的每个节点在被点击时,将触发一个事件,该事件根据边缘的权重从另一个边缘移除某些边缘。

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();正确?

1 个答案:

答案 0 :(得分:0)

您正在查询图表,然后对该查询结果中的元素调用restore。这意味着您正在对图表中已有的元素调用restore() - 无效。保留refs以删除元素以正确使用restore()