如果没有子's显示-工作不正常

Kendo UI treeview remove the expand arrow in kendo ui treeview if there are no child's to display - not working properly

本文关键字:显示 工作 不正常 如果没有      更新时间:2023-09-26

我试图使用此代码

如果没有子';s显示

现在,它不是选定的答案,但它对我部分有效

以下是我基于的hasChildren的答案

var inline = new kendo.data.HierarchicalDataSource({
    data: @Html.Raw(dataSource),
    schema: {
        model: {
            children: "Children",
            hasChildren: function(e) {
                var test = e.Children.length;
                return test > 0; 
            }
        }
    }
});

我的代码如下:

children: "items",
//hasChildren: "Id"  // Id I was using as that is a key 
hasChildren: function(e) {
    var test = e.items.length;
    return test > 0; 
}
  1. 数据负载看起来很棒。全部折叠,我看到只有带子节点的父节点才有箭头图标。完美
  2. 问题,一旦我单击展开任何父节点,我就会收到错误

    Uncaught TypeError: Cannot read property 'length' of undefined
    

为什么会发生这种情况?

听起来items属性有时为null。请先尝试检查它是否存在。

return e.items && e.items.length;