如何获取折叠的 Kendo TreeList 行?

How to get the collapsed Kendo TreeList row?

我有一个 Kendo TreeList 和绑定到 onCollapse() 方法的折叠事件。

我尝试使用 e.source 获取折叠的行,但那是 未定义的

在绑定到 dragstart、drop 和其他一些事件的方法中,e.source 是行,但在折叠事件中不是。

如何获取要折叠的行?

代码如下:

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();
    }
}

------------ 已解决(查看答案)-------- 解决方案:e.model

onCollapse: function (e) {
        if (e.model.Level == 0) {
            console.log("Prevent collapsing the ParentRow of all rows");
            e.preventDefault();
        }
    }

我刚刚尝试了一些东西,不确定你的数据看起来如何,但请看一下:

<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>

所以在这种情况下,它会写下折叠的项目的名称。

这里还有一个道场供测试:https://dojo.telerik.com/isiBaVEt

干杯