Reputation: 780
How can I traverse the nodes in a cytoscape js
network based on their selector?
I understand I can use the
cy.filter(".myselector")
which returns a complex object like:
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
Upvotes: 0
Views: 330
Reputation: 780
This is the method I developed to traverse the graph based on the selector (and obtain the element of interest, which in my case was the name of the node)
NB note how the name is retrieved, ie _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);
}
Upvotes: 1