簡體   English   中英

如何獲取折疊的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>

因此,在這種情況下,它將寫出折疊項的名稱。

這里還有一個用於測試的Dojo: https : //dojo.telerik.com/isiBaVEt

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM