0

我需要在我的应用程序屏幕上创建一个 toast,今天如果我多次单击一个按钮,则会显示几个 toast。

编辑:

showToast: function(message) {
    var openedToast = Ext.get(document.querySelector('[id^="toast-"]'));
    if (openedToast != null) {
        var toast = Ext.getCmp(openedToast.id);
        toast.close();
    }
    Ext.defer(function() {
        Ext.toast({
            html: message,
            align: 't'
        });
    }, 80);
}

但是如果用户快速点击按钮,toast 会创建几次

4

1 回答 1

2

只需给它一个唯一标识符并在创建新标识符之前检查它是否已经存在。

{
    xtype: 'button',
    handler: function(){
        if(!Ext.ComponentQuery.query('#myToast').length){
            Ext.toast({
                itemId: 'myToast',
                html: 'toast!'
            });
        }
    }
}

» 小提琴

于 2017-06-08T20:25:53.610 回答