使用 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()吗?正确吗?

您正在查询图,然后对该查询结果中的元素调用restore。这意味着你在图中已经存在的元素上调用restore()——没有效果。Keep是指为了正确使用restore()而删除的元素。

最新更新