This is a migrated thread and some comments may be shown as answers.

How to set children in kendo.observableHierarchy()?

2 Answers 290 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 21 Apr 2017, 10:56 AM

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 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 25 Apr 2017, 05:05 AM
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.
0
Marco
Top achievements
Rank 1
answered on 25 Apr 2017, 06:09 AM

Ah the schema was, what I was missing.

 

Thanks a lot - you deserve a beer :)

Tags
Hierarchical Data Source
Asked by
Marco
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Marco
Top achievements
Rank 1
Share this question
or