gpt4 book ai didi

kendo-ui - 如何在下拉列表中实现 Kendo Treeview

转载 作者:行者123 更新时间:2023-12-03 22:51:43 25 4
gpt4 key购买 nike

如何使用 Kendo UI for Web MVC 在下拉列表中加载 Treeview ?

最佳答案

Kendo UI Web“开箱即用”不支持下拉列表中的 Treeview 。但是,您可以让这两个控件协同工作,在下拉列表中为您提供 Treeview 的外观。我很快就把一些东西放在一起来演示。

我可以如下定义 HTML:

<ul id="treeview">
<li data-expanded="true">Item 1
<ul>
<li>Item 1.1</li>
<li>Item 1.2</li>
</ul>
</li>
<li data-expanded="true">Item 2
<ul>
<li>Item 2.1</li>
<li>Item 2.2</li>
</ul>
</li>
</ul>

<input id="dropdown"></input>

然后是这样的 JavaScript:
$(document).ready(function() {
var dropdown = $("#dropdown").kendoDropDownList({
dataSource: [{ text: "", value: "" }],
dataTextField: "text",
dataValueField: "value",
open: function (e) {
// If the treeview is not visible, then make it visible.
if (!$treeviewRootElem.hasClass("k-custom-visible")) {
$treeviewRootElem.slideToggle('fast', function() {
dropdown.close();
$treeviewRootElem.addClass("k-custom-visible");
});
}
}
}).data("kendoDropDownList");
var $dropdownRootElem = $(dropdown.element).closest("span.k-dropdown");

var treeview = $("#treeview").kendoTreeView({
select: function (e) {
// When a node is selected, display the text for the node in the dropdown and hide the treeview.
$dropdownRootElem.find("span.k-input").text($(e.node).children("div").text());
$treeviewRootElem.slideToggle('fast', function() {
$treeviewRootElem.removeClass("k-custom-visible");
});
}
}).data("kendoTreeView");
var $treeviewRootElem = $(treeview.element).closest("div.k-treeview");

// Hide the treeview.
$treeviewRootElem
.width($dropdownRootElem.width())
.css({ "border":"1px solid grey", "display": "none", "position": "absolute" });

// Position the treeview so that it is below the dropdown.
$treeviewRootElem
.css({ "top": $dropdownRootElem.position().top + $dropdownRootElem.height(), "left": $dropdownRootElem.position().left });

$(document).click(function(e) {
// Ignore clicks on the treetriew.
if ($(e.target).closest("div.k-treeview").length == 0) {
// If visible, then close the treeview.
if ($treeviewRootElem.hasClass("k-custom-visible")) {
$treeviewRootElem.slideToggle('fast', function() {
$treeviewRootElem.removeClass("k-custom-visible");
});
}
}
});
});

您可以从原始网页 http://www.telerik.com/forums/treeview-in-dropdownlist 下载示例代码

关于kendo-ui - 如何在下拉列表中实现 Kendo Treeview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22342444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com