我正在尝试在我的应用程序中实现 Sweet Alert javascript 库。
相关代码如下:
<xp:link escape="true" text="" id="link2" style="color:#4A4A4A">
<i class="fa fa-trash-o fa-lg">
</i>
<xp:eventHandler event="onclick"
submit="true" refreshMode="partial" refreshId="assetList">
<xp:this.action><![CDATA[#{javascript:
var db:NotesDatabase = session.getDatabase(sessionScope.serverPath,sessionScope.dbName);
var id = viewRow.getUniversalID();
var doc:NotesDocument = db.getDocumentByUNID(id);
doc.remove(true);}]]></xp:this.action>
<xp:this.script><![CDATA[swal({
title: "Are you sure?",
text: "This asset will be permanently deleted",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#2196f3",
confirmButtonText: "Ok",
cancelButtonColor: "#607D8B",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true,
confirmButtonClass: 'confirm-class',
cancelButtonClass: 'cancel-class'
},
function(isConfirm){
if (isConfirm) {
return true;
} else {
return false;
}
});
//if(window.confirm("Are you sure you want to delete the asset?") != true)
return false;]]></xp:this.script>
</xp:eventHandler>
</xp:link>
无论我做出什么选择(取消/确定),单击链接都会删除该行。我什至在做出选择之前就可以看到删除的发生。我感觉这与回调的执行顺序有关。
如果我使用最后注释掉的代码(window.confirm),它可以完美运行。
非常感谢您对此的指导。
谢谢
丹
最佳答案
问题在于,第 3 方提示不会像 native 浏览器提示那样阻止并等待响应,然后再继续。
这篇 SO 文章展示了一个将代码放入回调中以尝试使用 Sweet Alert 的示例(但看起来您已经在做类似的事情了): sweetalert blocking like normal prompt
触发将运行服务器端代码的按钮的单击事件即可完成工作。如果您希望它异步运行(但不需要更新页面客户端),您可以在回调中运行 json rpc 方法或调用自定义 REST 服务来运行服务器端代码,而不是触发隐藏按钮。
关于callback - SSJS 在 CSJS 回调函数之前执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043631/