1
votes

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

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

Here is the answer I based my hasChildren on

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

2
votes

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

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