首页 > 解决方案 > 如何处理@jupyterlab/apputils 对话框点击事件 | Jupyterlab 扩展

问题描述

根据文档https://jupyterlab.github.io/jupyterlab/apputils/classes/dialog.html,对话框构造函数获取按钮数组,其元素实现 IButton 接口。但是,IButton 没有任何 onclick 事件https://jupyterlab.github.io/jupyterlab/apputils/interfaces/dialog.ibutton.html

Dialog 有handleEvent 功能,但很难理解点击是从哪个按钮触发的。我找到的唯一解决方案是为按钮提供 ids/classes,使子节点不可点击(以便于比较),然后将 click 的 src 元素与所有按钮 ids/classes 进行比较。丑陋的解决方案:

dialog.handleEvent = e => {
  if (e.type === "click") {
    const elm: any = e.srcElement;
    if (elm.classList.contains("jp-Dialog")) {
      if (elm.classList.contains("cancel-btn")) {
        // handle cancel
      } else if(elm.classList.contains("success-btn")) {
        // handle success
      }
    }
  }
};

应该有更好的方法,但我什至通过检查文档都找不到。

标签: javascriptjupyter-notebookjupyter-lab

解决方案


推荐阅读