How to set children in kendo.observableHierarchy()?

3 posts, 0 answers
  1. Marco
    Marco avatar
    4 posts
    Member since:
    Feb 2017

    Posted 21 Apr Link to this post

    In a non-MVVM enviroment, I can define the child entities of my hierarchical datasource by setting the schema:

    var datasource = new kendo.data.HierarchicalDataSource({  
        data: [ /*... */ ],  
        schema: { 
            model: {
                children: "Assets"
            }
        }
    });

     

    In a viewModel I am defining the same datasource like this:

    function buildDataSource(data) {
         _.map(data.assets, function(item) {
            item.type = "folder";
       });
       var tree = unflatten(data.assets);
       return tree;
    }
     
    function loadTreeView(dataSource) {
        documentsModel.set("treeviewSource", kendo.observableHierarchy(dataSource));
        kendo.bind($("#Treeview"), documentsModel);
    }
     
    $.ajax({
         dataType: "json",
         url: "scripts/assets.json"
    })
    .then(buildDataSource)
    .then(loadTreeView);

     

    What is happening here, that I am loading a flat array of json objects from a file (later api endpoint) and unflatten this list, so it is in a hierachical format. The method to unflatten this array is naming the children "Assets". Running this, the treeview fails to display. If I change the unflatten method to name those children "items", the treebiew works.

    You can reproduce this in this Dojo: http://dojo.telerik.com/UTOBe/3

    Change items, to anything else and it stops working. How can I configure the kendo.observableHierarchy, so it uses any other property then "items" to determine if an object has children using a viewModel?

  2. Plamen
    Admin
    Plamen avatar
    2810 posts

    Posted 25 Apr Link to this post

    Hi,

    I have set the model in the sample that you provided and it worked correctly at my side. Here is the updated dojo page. Please let me know if you have your scenario is somehow different.

    Regards,
    Plamen
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Marco
    Marco avatar
    4 posts
    Member since:
    Feb 2017

    Posted 25 Apr in reply to Plamen Link to this post

    Ah the schema was, what I was missing.

     

    Thanks a lot - you deserve a beer :)

Back to Top