【发布时间】:2020-01-13 12:46:35
【问题描述】:
我有一个听MDCDialog:closing的小功能。
问题是,每次我运行这个函数时,它都会添加一个新的监听器。
所以,一旦我用完这个监听器,我就需要删除它。
到目前为止,这就是我所做的:
function confirm() {
mdcAlert.open();
// start listening
mdcAlert.listen("MDCDialog:closing", function(event) {
{... execute what need to be done ...}
// stop listening (not working)
mdcAlert.unlisten("MDCDialog:closing");
});
}
你知道如何使用unlisten吗?
我不知道如何在文档中使用它:
https://material.io/develop/web/components/dialogs/
https://pub.dev/documentation/mdc_web/latest/mdc_web/MDCComponent/unlisten.html
【问题讨论】:
-
你能检查是否已经有一个监听器,如果它不存在则只添加一个?
-
对不起@JimJimson,当我找到解决方案时忘记发布我的回复。刚刚发布。
标签: material-components material-components-web