我有一个Kendo UI Treeview,问题是当用户点击已经选择的节点时,不会触发select事件。除了使用jquery点击类元素触发事件之外,还有其他方法吗?
谢谢!
答案 0 :(得分:0)
请尝试使用以下代码段。
方法1:
<div id="treeview-left"></div>
<script>
var inlineDefault = new kendo.data.HierarchicalDataSource({
data: [
{
text: "Furniture", items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
]
},
{
text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
]
}
]
});
$("#treeview-left").kendoTreeView({
select: onSelect,
dataSource: inlineDefault
});
function onSelect(e) {
test();
}
$(document).on('click', '.k-state-selected', function () {
$("#treeview-left").data("kendoTreeView").trigger("select");
});
function test() {
//Your logic comes here
}
</script>
方法2:
<div id="treeview-left"></div>
<script>
var inlineDefault = new kendo.data.HierarchicalDataSource({
data: [
{
text: "Furniture", items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
]
},
{
text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
]
}
]
});
$("#treeview-left").kendoTreeView({
select: onSelect,
dataSource: inlineDefault
});
function onSelect(e) {
test();
}
$(document).on('click', '.k-state-selected', function () {
test();
});
function test() {
//Your logic comes here
}
</script>
如果有任何疑虑,请告诉我。