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

Sample of defining a Kendo UI Model with TypeScript

1 Answer 202 Views
Integration with other JS libraries
This is a migrated thread and some comments may be shown as answers.
Long
Top achievements
Rank 1
Long asked on 07 Apr 2014, 05:27 AM
Could you provide an example of defining a Kendo UI Model an Id and Fields using TypeScript?

class customerModel extends kendo.data.Model {
    constructor() {
        super();
        super.init(this);
        this.id = "CustomerID";
        this.fields = new kendo.data.DataSourceSchemaModelFields();
    }
}

This is far as I've gone by looking at Kendo.all.d.ts.

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 08 Apr 2014, 08:20 AM
Hello,

Here is a quick example using kendo.data.Model.define

var MyModel = kendo.data.Model.define(
    {
        id: "CustomerID",
        fields: {
            "CustomerID": { type: "number" },
            "CustomerName": { type: "string" }
        }
    });

window.onload = (e) => {
    var model = new MyModel({
        CustomerID: 1,
        CustomerName: "John Doe"
    });

    alert(model.id);
    alert(model.get("CustomerName"));
};

You need to use the define method if you want to specify the fields configuration option.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Integration with other JS libraries
Asked by
Long
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or