gpt4 book ai didi

javascript - cytoscape js 通过选择器遍历节点

转载 作者:行者123 更新时间:2023-12-02 23:34:23 24 4
gpt4 key购买 nike

如何根据选择器遍历 cytoscape js 网络中的节点?

我知道我可以使用

cy.filter(".myselector")

它返回一个复杂的对象,例如:

0: ua {0: ua, length: 1, _private: Object, instanceString: function, spawn: function, spawnSelf: function, …}

1: ua {0: ua, length: 1, _private: Object, instanceString: function, spawn: function, spawnSelf: function, …}

2: ua {0: ua, length: 1, _private: Object, instanceString: function, spawn: function, spawnSelf: function, …}

_private: {cy: Wa, map: Map}

length: 3

最佳答案

这是我开发的基于选择器遍历图形的方法(并获取感兴趣的元素,在我的例子中是节点的名称)

注意名称是如何检索的,即_private.data.name

var entire_object, no_of_objects, objects_array = []; 
entire_object = cy.filter(".myselector"); //returns a complex object with nodes matching ".myselector" filter
no_of_objects = entire_object.length; //the number of cytoscape nodes

for (var i = 0; i < no_of_objects; i++){
object_name = {};
object_name = entire_object[i]._private.data.name;
objects_array.push(object_name);
}

关于javascript - cytoscape js 通过选择器遍历节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56344600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com