<script>var dataSource =newkendo.data.HierarchicalDataSource({data:[{name:"Documents",items:[{name:"Report.pdf",size:"1MB"},{name:"Presentation.pptx",size:"5MB"}]},{name:"Images",items:[{name:"photo1.jpg",size:"2MB"},{name:"photo2.png",size:"3MB"}]}],schema:{model:{children:"items",fields:{name:{type:"string"},size:{type:"string"}}}}});
dataSource.read();/* The result can be observed in the DevTools(F12) console of the browser. */console.log(dataSource.view().length);// displays 2</script>
<script>varCustomNode= kendo.data.Node.define({averageRating:function(){var movies =this.children.data();var rating =0;if(movies.length){
$.each(movies,function(){ rating +=this.rating;});
rating /= movies.length;}return rating.toFixed(2);}});var datasource =newkendo.data.HierarchicalDataSource({data:[{categoryName:"SciFi",items:[{movieName:"Inception",rating:8.8},{movieName:"The Matrix",rating:8.7}]},{categoryName:"Drama",hasAssignedMovies:true}],schema:{model:CustomNode}});
datasource.read();var category = datasource.data()[0];
category.load();/* The result can be observed in the DevTools(F12) console of the browser. */console.log(category.averageRating());// logs 8.75</script>
Related Members
schema.model - The data item (model) configuration. See the DataSource.schema.model configuration for all available options.