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

TreeView, TypeScript and Model Classes

4 Answers 157 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 06 Jun 2014, 09:14 AM
Hi,

I'm using in my new project telerik kendo controls with angularjs, furthermore I want to use TypeScript.
This combination looks really good, but now I have following problem.

I have a hierarchical datasource for a treeview. The datasource is populated with my own javascript model class.

01.module MyNamespace {
02.    'use strict';
03. 
04.    export class Cluster {
05.        public clusters: Cluster[];
06.        public parentId: string;
07.        public dateCreated: Date;
08.        public dateModified: Date;
09. 
10.        constructor(
11.            public id: string,
12.            public matrixId: string,
13.            public name: string,
14.            public position: number
15.            ) {
16. 
17.            this.clusters = [];
18.            this.dateCreated = new Date();
19.            this.dateModified = new Date();
20.        }
21.    }
22.}



If I try to get the selected node item, I get following typescript error:

            Build: Cannot convert 'kendo.data.Node' to 'MyNamespace.Cluster'


The problem is, that .dataItem returns a node object and not my model class. If i try to cast the return value, i get this error:

          Error: Cannot convert 'kendo.data.Node' to 'MyNamespace.Cluster': Type 'kendo.data.Node' is missing property 'clusters' from type 'MyNamespace.Cluster'. Type 'MyNamespace.Cluster' is missing property 'children' from type 'kendo.data.Node'



How can i get off this error?

Regards
Daniel




4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 06 Jun 2014, 10:02 AM
Hello Daniel,

Since the TreeView is working with Node instances, you should be able to make the cast if the Cluster class extends the kendo.data.Node class:

class Cluster extends kendo.data.Node

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Daniel
Top achievements
Rank 1
answered on 06 Jun 2014, 11:23 AM
Hi Alex,

thanks for the quick Response. That helps me a lot.

Regards
Daniel
0
Daniel
Top achievements
Rank 1
answered on 06 Jun 2014, 12:57 PM
Hi Alex,

after extending my model class I have another problem.
It is all ok with TypeScript compiling, but now the TreeView doesn't show any children more :(

Regards
Daniel
0
Alex Gyoshev
Telerik team
answered on 09 Jun 2014, 07:24 AM
Hello Daniel,

It is likely that you will need to call the Node constructor from yours, or that you'll need to set the hasChildren flag accordingly. If neither of these appear to help, please provide a runnable sample so that we can reproduce the issue.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or