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?