Class: Collection

Konva. Collection


new Collection()

Collection constructor. Collection extends Array.
This class is used in conjunction with Konva.Container#find
The good thing about collection is that it has ALL methods of all Konva nodes. Take a look into examples.

Source:
konva.js
Example
// find all rectangles and return them as Collection
const shapes = layer.find('Rect');
// fill all rectangles with a single function
shapes.fill('red');

Methods


<static> Collection.toCollection(arr)

convert array into a collection

Parameters:
Name Type Description
arr Array
Source:
konva.js

each(func)

iterate through node array and run a function for each node.
The node and index is passed into the function

Parameters:
Name Type Description
func function
Source:
konva.js
Example
// get all nodes with name foo inside layer, and set x to 10 for each
layer.find('.foo').each(function(shape, n) {
  shape.setX(10);
});

toArray()

convert collection into an array

Source:
konva.js