以下代码弹出烤面包机:
function showMessage(code, type) {
ConfigService.getErrorMessage(code).then(
function (msg) {
toaster.pop(type, msg);
}
);
}
但是当我点击一次按钮时,我有一个烤面包机,但是当我点击两个,三个等时,我有相同数量的烤面包机,但我的目标是只有一个烤面包机,怎么做?我读了一些关于回调的内容,但不知道如何应用它。
编辑:已解决
var clicked = false;
function timeoutInterval(){
clicked = false;
}
// types - error, info, wait, success, warning
function showMessage(code, type) {
if(!clicked){
clicked = true;
ConfigService.getErrorMessage(code).then(
function (msg) {
toaster.pop(type, msg);
setTimeout(timeoutInterval, 6000);
}
);
}
}
答案 0 :(得分:1)
你可以通过使用布尔值来保存动作的“状态”
var clicked = false;
function showMessage(code, type) {
if (!clicked){ // If the button has not been clicked
clicked = true;
ConfigService.getErrorMessage(code).then(
function (msg) {
toaster.pop(type, msg);
clicked = false; // Reset the state of the boolean;
}
);
}
}