根据文档https://jupyterlab.github.io/jupyterlab/apputils/classes/dialog.html,Dialog构造函数获取button数组,其元素实现IButton接口。但是,IButton没有任何onclick事件https://jupyterlab.github.io/jupyterlab/apputils/interfaces/dialog.ibutton.html。
对话框具有handleEvent功能,但是很难理解是从哪个按钮触发了单击。我发现的唯一解决方案是给按钮提供ID /类,使子节点变得不可思议(使比较容易),然后将click的src元素与所有按钮ID /类进行比较。 丑陋的解决方案:
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
}
}
}
};
应该有一个更好的方法,但是即使通过查看文档也找不到。