UPDATE2
只需更正您需要执行的代码
-
okCallback.call()
或添加括号()
就像'okCallback()`
- 进而
cancelCallback.call()
或添加括号cancelCallback()
在 - 的里面.then((selection)=>{})
它是一个匿名函数,需要调用而不仅仅是使用okCallback
所以里面的代码.then((selection)=>{})
becomes
if(selection){ okCallback.call();}else{ cancelCallback.call();}
UPDATE
以下选项已被弃用sweetalert 2.0
版本,
因此,如果您使用的是 ver,可以将代码更改为以下内容2.x
或升级自1.x
.
yii.confirm = function (message, okCallback, cancelCallback) {
swal({
text: message,
icon: 'warning',
buttons : {
cancel : {
text : "Oops! No",
value : null,
visible : true,
className : "",
closeModal : true
},
confirm : {
text : "Delete It Already",
value : true,
visible : true,
className : "",
closeModal : true
}
},
closeOnClickOutside: true
}).then((selection) => {
if(selection){okCallback;}else{cancelCallback;}
});
}
你可以覆盖 Yii2 默认值data-confirm
弹出窗口,代码如下:
基础知识是包含资产,然后添加以下 JS:
/**
* Override the default yii confirm dialog. This function is
* called by yii when a confirmation is requested.
*
* @param message the message to display
* @param okCallback triggered when confirmation is true
* @param cancelCallback callback triggered when canceled
*/
yii.confirm = function (message, okCallback, cancelCallback) {
swal({
title: message,
type: 'warning',
showCancelButton: true,
closeOnConfirm: true,
allowOutsideClick: true
}, okCallback);
};