Not rendering sub-items when full source is loaded via ajax

2 posts, 1 answers
  1. Matjaz
    Matjaz avatar
    94 posts
    Member since:
    Jun 2014

    Posted 19 Sep 2014 Link to this post

    I try with this code but it is not rendering childs:
    <body>
     <div id="main">
        <div data-role="treeview" data-bind="source: test" data-load-on-demand="true"></div>
    </div>
      
    <script>
    $(document).ready(function()
            {
                var MVVM = kendo.observable(
                {
                  test: new kendo.data.HierarchicalDataSource(
                            {
                                transport:
                                {
                                    read:
                                    {
                                        url: "GetTreeViewData.php"
                                    }
                                },                         
                            }),
                  });
                 kendo.bind($('#main'), MVVM);
            });
     
        
    </script>
     
    </body>
    My GetTreeViewData is:
    <?php
        $result = [];
     
        $item = new stdClass();
        $item->text = "level 1.1";
        $result[] = $item;
     
        $item = new stdClass();
        $item->text = "level 1.2";
        $item->items = [];
         
        $subitem = new stdClass();
        $subitem->text = "level 2.1";
        $item->items[] = $subitem;
     
        $subitem = new stdClass();
        $subitem->text = "level 2.2";
        $item->items[] = $subitem;
     
        $item = new stdClass();
        $item->text = "level 1.3";
        $result[] = $item;
         
        header('Content-type: application/json;');
        echo json_encode($result); 
    ?>

    I also try to experiments with hasChildren, children, loadOnDemand properties, without success.
    What I am doing wrong?
  2. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 23 Sep 2014 Link to this post

    Hello Matjaz,

    In order to bind all levels when the dataSource is loaded, you will need to specify a schema that does this. See this documentation help topic for a demo.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top