cytoscape.js 中的一些节点添加不同的 href

Add diffrenet href to some nodes in cytoscape.js

我为一些节点设置了 href,它工作正常,但其他节点打开空白页是否可以让它们没有 href 并且不打开空白页?

我用它来制作 href :

cy.nodes('[id = "start"]').data('href', 'https://js.cytoscape.org/');

cy.on('tap', 'node', function() {
  try {
    window.open(this.data('href'));
  } catch (e) {
    window.location.href = this.data('href');
  }
});

是的,侦听来自 node[href] 的事件,这意味着在其数据集中有 href 的节点。

cy.on('tap', 'node[href]', function() {})

我对此不是很确定,但应该可以。 如果没有,只需添加

if (!this.data('href')) return;

作为处理程序中的第一行。