我在对话框中呈现了一个 TreeView。使用对话框我有一个清除选择按钮,我的问题是如何将树视图恢复到默认的未展开状态。
目前,如果我展开树视图中的节点并点击清除按钮并再次打开对话框,树视图仍然展开。
在我的 Dailog 框 Javascript 文件的 document.ready 上,我有以下内容来初始化树视图。我应该把它放在一个函数中,然后在对话框中的清除按钮上,再次调用这个函数来重置?
JS文件
//This load the tree view on document ready
$("#parts ul").treeview({
persist: "location",
collapsed: true,
prerendered: false
});
Clear: function () {
$('#partTreeView :checked').removeAttr('checked');
$("#PartDisplay").text('');
$("#inputReps").text('');
$("#parts").attr("style", "display:inline;");
$("#inputParts").attr("style", "display:none;");
PartDialog.dialog("destroy");
//Toggle/Un-expand tree view here if already expanded here
}
查看 HTML
<!-- This div opens the dialog box -->
<div class="bodyContent">
<span class="leftContent">
@Html.Label("Select Parts")
</span>
<span class="rightContent">
<span id="PartChildDialogLink" class="treeViewLink">Click here to Select Parts</span>
<br />
<span id="PartDisplay"></span>
@Html.HiddenFor(model => model.PartDescription)
<input id="ServiceEntryID" type="hidden" value="0" />
</span>
</div>
<!-- This div contains the dialog box and the tree viwe rendered inside of it -->
<div id="partTreeView" title="Dialog Title" style="font-size: 10px; font-weight: normal; overflow: scroll; width: 800px; height: 450px; display: none;">
<div id="parts">
<!-- This line renders the treeview just fine -->
@Html.RenderTree(CacheHelper.Parts(), ec => ec.Name, ec => ec.Children.ToList(), ec => (ec.ID).ToString(), null, "part")
</div>
<div id="inputParts" style="display: none;"></div>
<div id="inputPartTemp" style="display: none;"></div>
</div>