我是Kendo控件的新手,请帮助我,如附件所示,我已经具有Tree View了,现在我有两个(Expand和Collapse)按钮,我需要在单击时执行“ Expand All”单击“折叠”按钮,展开按钮和“全部折叠”。
如何通过单击“扩展”按钮和“折叠”按钮在Kendo树状视图中执行“全部扩展”和“全部折叠”。
请帮助我。
答案 0 :(得分:1)
对此有类似/相同的问题,请检查this, 您需要在那里结合答案。基本上:
喜欢:
<!DOCTYPE html>
<html>
<head>
<base href="https://demos.telerik.com/kendo-ui/treeview/index">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.material.mobile.min.css" />
<script src="https://kendo.cdn.telerik.com/2018.3.911/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.3.911/js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
<button id="expand">Expand All</button>
<button id="collapse">Collapse All</button>
<div class="demo-section k-content">
<ul id="treeview">
<li data-expanded="true">
<span class="k-sprite folder"></span>
My Web Site
<ul>
<li data-expanded="true">
<span class="k-sprite folder"></span>images
<ul>
<li><span class="k-sprite image"></span>logo.png</li>
<li><span class="k-sprite image"></span>body-back.png</li>
<li><span class="k-sprite image"></span>my-photo.jpg</li>
</ul>
</li>
<li data-expanded="true">
<span class="k-sprite folder"></span>resources
<ul>
<li data-expanded="true">
<span class="k-sprite folder"></span>pdf
<ul>
<li><span class="k-sprite pdf"></span>brochure.pdf</li>
<li><span class="k-sprite pdf"></span>prices.pdf</li>
</ul>
</li>
<li><span class="k-sprite folder"></span>zip</li>
</ul>
</li>
<li><span class="k-sprite html"></span>about.html</li>
<li><span class="k-sprite html"></span>contacts.html</li>
<li><span class="k-sprite html"></span>index.html</li>
<li><span class="k-sprite html"></span>portfolio.html</li>
</ul>
</li>
</ul>
</div>
<script>
$(document).ready(function() {
$("#treeview").kendoTreeView();
$("#expand").on("click", function(){
var treeview = $("#treeview").data("kendoTreeView");
treeview.expand(".k-item");
})
$("#collapse").on("click", function(){
var treeview = $("#treeview").data("kendoTreeView");
treeview.collapse(".k-item");
})
});
</script>
<style>
#treeview .k-sprite {
background-image: url("../content/web/treeview/coloricons-sprite.png");
}
.rootfolder { background-position: 0 0; }
.folder { background-position: 0 -16px; }
.pdf { background-position: 0 -32px; }
.html { background-position: 0 -48px; }
.image { background-position: 0 -64px; }
</style>
</div>
</body>
</html>