getting name attribute of a group fails (on the second time) in konvajs

Viewed 15

I have 3 groups each contain a rect and a text. When creating each group I set "name" attribute to "false". Then I add these groups to an array called "groups". The problem is, that I want to get the "name" attribute when I do dragstart on one of these groups. I get the "name" only when I drag these groups for the first time. Meaning I startdrag the first - it works, second - works, third - works, but dragging one of them twice fails with "groups[i].name is not a function". That I dont understand, since it worked the first time.

this is how I created groups:

var group1 = new Konva.Group({
    x: 30,
    y: 50,
    draggable: true,
    name: "false",
});

var text1 = new Konva.Text({
    fontSize: 26,
    fontFamily: 'Calibri',
    text: 'Hello',
    fill: 'black',
    padding: 10,
});

var rect1 = new Konva.Rect({
    width: text1.width(),
    height: text1.height(),
    fill: '#aaf',
});

then I added them to a group like this:

group1.add(rect1).add(text1);

I created an array and pushed these groups in:

var groups = [];
groups.push(group1, group2, group3);

I iterate groups and assign each 'dragstart' event in which I came across my problem when logging

for (let i = 0; i < groups.length; i++) {
    groups[i].on('dragstart', () => {

        console.log(groups[i].name());
    })
0 Answers
Related