[英]How to get the collapsed Kendo TreeList row?
I have a Kendo TreeList and the collapse event bound to an onCollapse()
method. 我有一个Kendo TreeList和一个绑定到
onCollapse()
方法的崩溃事件。
I've tried to get the collapsed row with e.source
but that's undefined . 我试图用
e.source
获取折叠行,但这是未定义的 。
In methods bound to dragstart, drop and some other events, e.source
is the row, but not in the collapse event. 在绑定到dragstart,drop和其他事件的方法中,
e.source
是行,而不是折叠事件。
How can I get the row intended to collapse? 如何获得要折叠的行?
Here is the code: 这是代码:
onCollapse: function (e) {
console.log(e.source) //undefined
var row = **?** ;
var dataItem = treeList.dataItem(row);
if (dataItem.Level == 0) { //my dataitems have levels
console.log("Prevent collapsing the ParentRow of all rows");
e.preventDefault();
}
}
----------- solved (see answer) -------- solution: e.model ----------- 解决 (请参阅答案)--------解决方案: e.model
onCollapse: function (e) {
if (e.model.Level == 0) {
console.log("Prevent collapsing the ParentRow of all rows");
e.preventDefault();
}
}
I just tried something, not sure how your data looks, but take a look: 我只是尝试了一下,不确定您的数据看起来如何,但请看一下:
<script>
$("#treeList").kendoTreeList({
columns: [
{ field: "Name" },
{ field: "Position" }
],
dataSource: [
{ id: 1, Name: "Daryl Sweeney", Position: "CEO", parentId: null, expanded: true },
{ id: 2, Name: "Guy Wooten", Position: "Chief Technical Officer", parentId: 1 }
],
collapse: function(e) {
console.log("collapse", e.model);
console.log("collapse", e.model.Name); //will get Daryl Sweeney
}
});
</script>
So in this case it will write the name of the item that collapses. 因此,在这种情况下,它将写出折叠项的名称。
Here also a Dojo for testing: https://dojo.telerik.com/isiBaVEt 这里还有一个用于测试的Dojo: https : //dojo.telerik.com/isiBaVEt
Cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.