用于templates
定义树的每个节点的外观,您可以定义任何可能的HTML
和JavaScript
。
示例:定义一个节点,我们在其中显示每个节点text
和三个 HTML 锚点 ( a
)。然后,我们将一个click
事件绑定到每个链接,如下所示:
模板定义
<script id="treeview-template" type="text/kendo-ui-template">
<div class="ob-item">
<div>#: item.text #</div>
This is <a class='link1' href='\#'>Link 1</a>
and this is <a class='link2' href='\#'>Link 2</a>
and finally <a class='link3' href='\#'>Link 3</a>
</div>
</script>
定义TreeView
:
var treeview = $("#treeview").kendoTreeView({
template: kendo.template($("#treeview-template").html()),
dataSource: [
...
]
});
绑定事件:
$(document).on("click", ".link1", function (e) {
treeview = $("#treeview").data("kendoTreeView");
var node = $(this).closest(".k-item");
var item = treeview.dataItem(node);
alert("Clicked on link1 of node with id: " + item.id + " and text: " + item.text);
});
$(document).on("click", ".link2", function (e) {
treeview = $("#treeview").data("kendoTreeView");
var node = $(this).closest(".k-item");
var item = treeview.dataItem(node);
alert("Clicked on link2 of node with id: " + item.id + " and text: " + item.text);
});
$(document).on("click", ".link3", function (e) {
treeview = $("#treeview").data("kendoTreeView");
var node = $(this).closest(".k-item");
var item = treeview.dataItem(node);
alert("Clicked on link3 of node with id: " + item.id + " and text: " + item.text);
});
在http://jsfiddle.net/OnaBai/hv4FV/1中显示的 JSFiddle