forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Collection each
maxkfranz edited this page Mar 8, 2012
·
3 revisions
Call a callback function for each element in the collection.
Calls the specified callback function on each element in the collection
function(i, element) : The callback function to execute for each element in the collection
i: The index of the element in the collection
element: The current element
This function is useful for iterating over the elements in a collection. You can break early by returning false:
cy.nodes().each(function(i, ele){
ele.data("foo", "bar");
if( ele.selected() ) return false;
});
// this is the same
var nodes = cy.nodes();
for(var i = 0; i < nodes.size(); i++){
var ele = nodes.eq(i);
ele.data("foo", "bar");
if( ele.selected ) break;
}cy.nodes().each(function(i, element){
console.log( "Looking at node `%s`", element.data("id") );
});