【问题标题】:GoJS - Click event strange behaviour, "this" ends up being nullGoJS - 单击事件奇怪的行为,“this”最终为空
【发布时间】:2020-10-08 12:10:06
【问题描述】:

当我的 GoJS 图被点击时,我想更新一些列表面板。 click 事件每次都会触发,但有时this 最终会在事件中成为null,我无法访问面板的其余部分。任何想法为什么会这样?

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);
        }
    }); 

谢谢!

【问题讨论】:

    标签: events click gojs


    【解决方案1】:

    使用eobj 参数代替this,这在JavaScript 中很难预测,因为您不知道调用事件的上下文。

    【讨论】:

    • 谢谢,我使用 GraphObject 来查找我的列表面板。
    • 对此有一点更新。我设法通过在包含事件定义的父函数中添加以下内容来解决这个问题:let me = this;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多