【问题标题】:How can I inject a variable in selectors in Cytoscape JS?如何在 Cytoscape JS 的选择器中注入变量?
【发布时间】:2021-11-20 15:36:37
【问题描述】:

我试图通过根据 id 字段选择边来可视化具有不同宽度的图形的边。是否可以在选择器查询中使用变量?我怎样才能实现这种行为?有一些方法可以通过重复代码来解决这个问题,例如:

if (i==0){  
        edge_item = cy.elements('edge[id = "edge_0"]');

        cy.style()
          .selector(edge_item)
          .style({
          'width': 10
          })
          .update();
      }

然而,我更喜欢更简洁的解决方案,最好使用变量而不是上面的“edge_0”,如下所示:

edge_var = "edge_" + i;
edge_item = cy.elements('edge[id = "edge_var"]');

这可能吗?

【问题讨论】:

    标签: javascript selector cytoscape


    【解决方案1】:

    显然,这是通过转义字符完成的。

    var nodeId = "edge_";
      for (var i = 0; i < 60; i++) {
      cy.remove('edge[id=\'' + nodeId.concat(i.toString()) + '\']');
      }
    

    我在类似的环境中遇到了this post here 的答案。

    【讨论】:

      猜你喜欢
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 2015-07-26
      • 2016-01-12
      相关资源
      最近更新 更多