2

It there any way to set/get data in konva object?

Just like jquery use the method 'data' to set and get info,eg: $('#abc').data('id','123') !

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
Jack
  • 35
  • 4
  • Hi and welcome - looks like you have a viable answer from @lavrton below. If this works for you then please click the tick to mark it as the accepted answer. If not then add a comment on that answer and help us to know why it will not work for you so that we can suggest alternatives. – Vanquished Wombat Mar 27 '19 at 17:36

1 Answers1

7

You can use custom attributes. Just make sure they don't overlap with built-in properties.

https://konvajs.org/api/Konva.Node.html#setAttr

https://konvajs.org/api/Konva.Node.html#getAttr

// set
shape.setAttr('someData', 0);
// get
shape.getAttr('someData');
lavrton
  • 18,973
  • 4
  • 30
  • 63