简体   繁体   English

Cytoscape.js通过编程将节点设置为活动状态

[英]Cytoscape.js set node active programmatically

I need to set node selected inside my function where I create it 我需要在创建函数的地方设置选中的节点

cy.on('tap', function (e) {
    if (!e.target.id) {
        let x = e.position.x;
        let y = e.position.y;
        let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y}};
        cy.add(new_node);
        // make node selected (click on it)
    }
});

Then i will get created node data like I get it from other nodes 然后我将获得创建的节点数据,就像我从其他节点获得的一样

selected = cy.$('node:selected').jsons();

How can I do it? 我该怎么做?

The solution was simple. 解决方案很简单。 I added selected: true to initialisation 我添加了选择:true初始化

let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y}, selected: true};

Try this 尝试这个

let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y},classes : 'selected'};

and then 接着

cy.$('node.selected')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM