将diffrenet href添加到cytoscape.js中的某些节点

问题描述 投票:0回答:1

我为某些节点设置了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');
                        }
                    });
javascript cytoscape.js
1个回答
0
投票

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

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

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

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

作为处理程序的第一行。

© www.soinside.com 2019 - 2024. All rights reserved.