我有一段時間以來一直困擾着我的情況。我在我的項目中設置了一個Kendo UI樹形視圖,如http://demos.telerik.com/kendo-ui/web/treeview/events.html所述。Kendo UI Treeview摺疊所有項目,只展開當前節點
我需要實現的是當我在樹狀視圖上展開一個節點時,不在此分支中的所有其他節點都應該摺疊並且在此分支上展開。我試過使用下面的代碼,但不幸的是它進入了一個無限循環。
<div id="example" class="k-content">
<div id="treeview" class="demo-section" style="width: 200px"></div>
<div class="demo-section">
<h3 class="title">Console log
</h3>
<div class="console"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
function onExpand(e) {
e.preventDefault();
kendoTreeView.collapse('.k-item');
kendoTreeView.expand(e.node);
}
$("#treeview").kendoTreeView({
dataSource: [
{ text: "Furniture", expanded: true, items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
] },
{ text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
] },
{ text: "Storage" }
],
expand:OnExpand
});
});
</script>
請幫忙。
謝謝
超級酷。輝煌。這工作。你剛剛度過了我的一天。謝謝@OnaBai。 –