【发布时间】:2016-05-19 16:44:52
【问题描述】:
我在 mvc 页面中添加了一个 jquery UI 对话框。打开对话框后,如果对话框被 dismissed 或 confirmed,我需要捕获 bool 值。
到目前为止,我已尝试添加另一个答案中提到的回调,但我不确定如何将该值传递回$('#escalation').on('click', '.delete', function (evt),以便如果为真我可以执行重定向。
问题:
如何将布尔值从 Jquery UI 模式对话框传回调用函数?
伪代码:
这是我对以下功能的预期执行流程:
1.点击按钮打开调用对话框。 - (工作)
2.根据用户在模态对话框中选择“确定”还是“取消”返回真或假。
3.如果按钮点击事件的返回结果为假,则关闭对话框。否则调用
window.location.href = RedirectTo;代码。
代码:
对话框标记 -
<div id="dialog-confirm" title="Delete Selected Record?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This record will be permanently deleted.</p> <p>Are you sure?</p>
</div>
Jquery 脚本 -
<script>
var baseUri = '@Url.Content("~")';
$(document).ready(function () {
$('#escalation').DataTable({
"order": [[6, "desc"]]
});
$('#escalation').on('click', '.delete', function (evt) {
var cell = $(evt.target).closest("tr").children().first();
var EscalationID = cell.text();
var RedirectTo = baseUri + "/EscalationHistory/DeleteEscalation?EscalationID=" + EscalationID;
////open dialog
evt.preventDefault();
$("#dialog-confirm").dialog("open");
//Need to call this code if the dialog result callback equals true
window.location.href = RedirectTo;
//Otherwise do nothing..close dialog
});
//Dialog opened here, not sure how to pass back the boolean values
//to the delete click function above
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true,
buttons: {
"Confirm": function () {
callback(true);
},
"Cancel": function () {
$(this).dialog("close");
callback(false);
}
}
});
});
</script>
【问题讨论】:
标签: javascript jquery function callback jquery-ui-dialog