如果没有要显示的子项,Kendo UI treeview会删除kendo ui treeview中的展开箭头 - 无法正常工作

时间:2021-02-02 03:55:21

I was attempting to use this code

我试图使用此代码

How can i remove the expand arrow in kendo ui treeview if there are no child's to display

如果没有要显示的子项,如何删除kendo ui treeview中的展开箭头

Now, it is not the selected answer, but it is partially working for me

现在,它不是选定的答案,但它对我来说是部分工作

Here is the answer I based my hasChildren on

这是我基于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; 
            }
        }
    }
});

My code looks like this:

我的代码如下所示:

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. The load of the data looks great. All collapsed and I see that ONLY the parent nodes WITH children have Arrow icons . Perfect
  2. 数据的负载看起来很棒。所有折叠,我看到只有带子节点的父节点有箭头图标。完善

  3. Problem, as soon as I click to expand any Parent Node I get an error

    问题,只要我点击展开任何父节点我就会收到错误

    Uncaught TypeError: Cannot read property 'length' of undefined
    

Why is this happening?

为什么会这样?

1 个解决方案

#1


2  

It sounds like the items property is sometimes null. Give a try to check if it exists first.

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

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

#1


2  

It sounds like the items property is sometimes null. Give a try to check if it exists first.

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

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