我正在尝试编写自己的方法,调用BootstrapDialog并创建确认弹出窗口。如果用户选择“确认”,则该方法将返回true并继续调用jsf操作。我目前拥有的代码:
/**
* Confirm window
*
* @param {type} message
* @param {type} callback
* @returns {undefined}
*/
BootstrapDialog.confirmation = function(title, message) {
var callback = function(result) {
console.log(result);
return result;
};
var b = new BootstrapDialog({
title: title,
message: message,
closable: false,
data: {
'callback': callback
},
buttons: [{
label: 'Cancel',
action: function(dialog) {
typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(false);
dialog.close();
}
}, {
label: 'Continue',
cssClass: 'btn-primary',
action: function(dialog) {
typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(true);
dialog.close();
}
}]
}).open();
return callback;
};
我正在这样调用js:
我正在这样调用js:
<h:commandButton type="button" value="Exit" action="myaction" styleClass="btn btn-default" onclick="return BootstrapDialog.confirmation('Data unsaved', 'Are you sure you want to continue');"/>
弹出对话框显示正常,问题在于它没有返回 true / false。我参考了这个示例的 js:http://nakupanda.github.io/bootstrap3-dialog/
confirm
会阻止浏览器直到用户采取行动。这就是为什么它能够被同步处理的原因。Bootstrap的对话框并不是设计成那样操作的。例如,当对话框出现时,用户仍然可以点击页面的其他部分,而使用本机确认对话框时则不能这样做。问题是当用户点击继续并确认意图后,您想要发生什么。重定向到另一个页面?提交表单?这就是您放在letUserExit
中(或直接在“继续”按钮回调中)的内容。 - klenwell