如何在 Extjs 中创建单例 Toast
How to create a singleton Toast in Extjs
我需要在我的应用程序屏幕上创建一个 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
只需给它一个唯一标识符,并在创建新标识符之前检查它是否已经存在。
{
xtype: 'button',
handler: function(){
if(!Ext.ComponentQuery.query('#myToast').length){
Ext.toast({
itemId: 'myToast',
html: 'toast!'
});
}
}
}
我需要在我的应用程序屏幕上创建一个 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
只需给它一个唯一标识符,并在创建新标识符之前检查它是否已经存在。
{
xtype: 'button',
handler: function(){
if(!Ext.ComponentQuery.query('#myToast').length){
Ext.toast({
itemId: 'myToast',
html: 'toast!'
});
}
}
}