如何获取 Kendo TreeList 自定义 createChild 命令的行索引

How to Get the Row Index of a Kendo TreeList Custom createChild Command

我有一个 Kendo TreeList,其中包含以下自定义命令:

{
    command: [
        {
            name: "Edit",
            imageClass: "fa fa-pencil"
        },
        {
            name: "Delete",
            imageClass: "fa fa-trash"
        },
        {
            name: "createChild",
            imageClass: "fa fa-plus"
        }
    ], title: "Actions", width: "300px"
}

我点击创建子按钮,输入我的数据并点击"Update"。这将我带到 Kendo 数据源的 "create" 定义:

create: function (e) {//Called when the create child command is saved
    //Collect the data needed for the save
}

此时我需要获取新行的行索引,但似乎找不到正确的方法。我试过类似的东西:

$(e.target).closest("tr").parent().index()

但这给出了-1

并且:

var selectedRow = $scope.treelist.select();
var node = $scope.treelist.dataItem(selectedRow);

但是节点未定义

有什么想法吗?

事实上,您没有将行引用到 create 事件的范围内。但是,您可以在小部件的 DOM:

中找到该元素
var index = $($("#grid").data("kendoTreeList").element).find(".k-grid-edit-row").index();

活动编辑行收到 k-grid-edit-row class,您可以在小部件的 DOM 树中轻松找到它。

Working Demo.

不确定这是否是您真正想要的。