javascript - 如何处理@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
}
}
}
};
应该有更好的方法,但我什至通过检查文档都找不到。
解决方案
推荐阅读
- java - 如何在 ActiveMQ Artemis 集群中启用 REST
- reactjs - Making React aware of the custom configured CDN headers
- laravel - having issues on sending email in laravel 5.8
- flutter - 通过 pubspec.yaml 从内部存储库中提取依赖项
- reactjs - 通过导航更改的 ScrollToTop 不起作用
- google-cloud-platform - Is there a way to detect cold start in Google Cloud Functions?
- python - Check if a string contains a string except a list
- yaml - 如何在 WebStorm 中为 YAML 内容启用拼写检查
- python - 为什么在熊猫数据框中与 dict 进行键值匹配后我有 NAN?
- sql - 尝试使用左连接连接两个表,输入列出现分析异常错误?