2
votes

I have got a Kendo TreeView:

@(Html.Kendo().TreeView()
    .Name("treeview")
    .BindTo((IEnumerable<TreeViewItemModel>)ViewBag.MyTree)
    .Events(e => e.Select("test"))
)

Here's the Javascript function fired when selecting a node:

function test(e) {
    var id = $(e.node).data("id");
    var description = this.text(e.node);
    //if (.....) {
    //   ..... something here 
    //}
    alert('Id: ' + id + '\nDescription: ' + description);
}

The above shows an alert with the Id and Text of the node. Now, I want to check if the selected node has siblings or children and do something if it does, and some other thing if it doesn't.

How can I achieve it?

1

1 Answers

2
votes

You can check for siblings with e.node.parentNode.childNodes.length - 1 and for children with e.node.childNodes.length - 1