簡體   English   中英

Cytoscape.js通過編程將節點設置為活動狀態

[英]Cytoscape.js set node active programmatically

我需要在創建函數的地方設置選中的節點

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)
    }
});

然后我將獲得創建的節點數據,就像我從其他節點獲得的一樣

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

我該怎么做?

解決方案很簡單。 我添加了選擇:true初始化

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

嘗試這個

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

接着

cy.$('node.selected')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM