Treeview with no children says it has children (solved)

1 posts, 0 answers
  1. Tayger
    Tayger avatar
    192 posts
    Member since:
    Jan 2015

    Posted 03 Jul 2017 Link to this post

    This is solved and doesn't need to be answered. I just put it here in case someone runs into the same problem.

    A treeview item says it has children altough there are no children by using "hasChildren":

    <!DOCTYPE html>
    <html lang="en">
            <meta charset="UTF-8">
            <script src="" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
            <link rel="stylesheet" href="" />
            <link rel="stylesheet" href="" />
            <script src=""></script>
            <script src=""></script>
            $(document).ready(function() {
                // Bind dropdownlist
                    animation: false,
                    dataSource: [
                        { 'id': '1', 'text': 'One child entry', 'expanded': 'true', "items": [ {'id': "2", 'text': "No child entry", "items": []} ] }
                    select: function(e) {
                        var treeItem = this.dataItem(e.node);
                        if (treeItem.hasChildren) { alert ("Entry has children"); }
                        else { alert ("Entry has no children"); }
            <div id="mytree" style="clear: both;"></div>


    You can run this code and click on the treeview entry "No child entry". It will tell you it has children! Why? The problem is on the predefinition in the datasource: ... ,"items": []

    Remove that and it will work fine. I thought the Treeview Widget would take that over or replace it. But since it outputs wrong result, don't use it that way.


Back to Top