我的视图中有两个对话框。这些对话框中的每一个都有 ajax 命令,例如第一个执行 a POST
,第二个执行 a LOAD
。
问题是在我从对话框 1 中的复选框列表中选择并点击 UpdatePage 按钮后,我的模型更新得很好。但是,包含带有另一个 checbobox 列表/节点的树视图的第二个对话框根本不会切换。但它确实保留了以前的状态:先前选择的复选框已选中,但根本不会切换。
以下函数创建对话框 1,并且在成功完成此对话框中的 post 命令后,第二个对话框和其中的树视图将不会切换。
function initDailog() {
RunDialog = $("#runDatestreeview").dialog({ closeOnEscape: true, stack: false, autoOpen: true,
modal: false, resizable: true, draggable: true, title: 'Select Run Dates to Auto-Populate Form Fields & Test Exceptions:',
width: 600, height: 500, position: 'center',
open: function (type, data) {
},
buttons: { UpdatePage: function () {
//storing the value of treeview selections in dialog box 2
var originalContent = $("#treeview").html();
$.post(runDatesUrl,
$("#form").serialize(),
function (data) {
$("#runDatestreeview").remove();
//removing the div which contains the treeview
$("#treeview").remove();
$("#testExceptiontreeview").remove();
$("#main").html(data);
//setting back the value of the div which contains the treeview
$("#treeview").html(originalContent);
}, "html");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
RunDialog.closest("div.ui-dialog").appendTo("#form");
}
在对话框 2 中定义的 Treeview,在其单独的 JS 文件中:
$("#errorCodes ul").treeview({
collapsed: true,
prerendered: false
});
包含树视图的 div 的 HTML:
<div id="treeview" title="Dialog Title" style="font-size: 10px; font-weight: normal;
overflow: scroll; width: 800px; height: 450px; display: none;">
<div id="errorCodes">
@Html.RenderTree(CacheHelper.ErrorCodes(), ec => ec.Name, ec => ec.Children.ToList(), ec => (ec.ID).ToString(), null, "e")
</div>
<div id="inputReps" style="display: none;">
</div>
</div