GoJS - Click event strange behaviour, "this" ends up being null

250 views Asked by At

I would like to update some list panels when my GoJS diagram is clicked. The click event fires everytime, but sometimes this ends up being null within the event, and I can't access the rest of my panel. Any ideas why this might be?

myDiagram.linkTemplate =
    $(Link,
    $(Shape,
        { strokeWidth: 1, stroke: "gray" },
    $(Shape, new Binding("fromArrow", "fa")),
    $(Shape, new Binding("toArrow", "ta")),
    {
        click: (e: go.InputEvent, obj: go.GraphObject, ) => {
            console.log('[nav123] starting click');
            this.listPanelA.scrollToRow(obj['pb'].rowNumber);
            this.listPanelB.scrollToRow(obj['pb'].rowNumber);
        }
    }); 

Thanks!

1

There are 1 answers

2
Simon Sarris On BEST ANSWER

Use the e and obj arguments instead of this, which is difficult to predict in JavaScript, because you do not know the context that calls the event.