Kendo UI HierarchicalDataSource schema not working

2.2k Views Asked by At

I have a kendo tree which i am trying to bind it to a local json arrray.

Trying to map my json object properties to what treeView expects is not working.

The value of the "text" property is the function definition (function (item){ return item.Text; }) The function itself doesn't gets evaluated

jsfiddle

Html:

<div id="tree"></div>

Javascript:

var data = [
    {
       "Text": "Some dummy text"
    }
];

var inlineDefault = new kendo.data.HierarchicalDataSource({
    data: data,
    schema: {
        model: {
            text: function(item){
                return item.Text;
            }
        }
    }
});

$("#tree").kendoTreeView({
    dataSource: inlineDefault
});
2

There are 2 best solutions below

0
On

Defining a schema model in this way is not supported - see the options here,the additional field for hierarchical data sources here and an example on how to create a tree view here.

0
On

Instead of using projection in the data source, use the TreeView dataTextField to define where your data is located:

var data = [
    {
       "Text": "Some dummy text"
    }
];

var inlineDefault = new kendo.data.HierarchicalDataSource({
    data: data
});

$("#tree").kendoTreeView({
    dataTextField: "Text",
    dataSource: inlineDefault
});