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

Model, DataSource and Date

0 Answers 79 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Luc
Top achievements
Rank 1
Luc asked on 20 Nov 2012, 11:39 PM
Hello,

I'm trying to user the kendo.data.Model to make an observable object from a single object retrieved from a web service.
When I do a kendo.data.Model.define(...), the fields are entirely ignored, and the field containing the date is mapped to a string.

If I create a datasource with the exact same model, I retrieve a correct date.

I tried to put a custom parse function, and in the first case, nothing happen.
In the second scenario, I can see my parse method called.

Here is a sample of what I do :
var obj = {
    Id: "1",
    Name: "foo",
    Age: "28",
    Fire: "/Date(1348479856993)/"
};
 
var objModel = kendo.data.Model.define({
    id: "Id",
    fields: {
        Id: { type: "number" },
        Name: { type: "string", parse: function(e) {
                debugger;
                return e;
            }
        },
        Fire: { type: "date" },
        Age: { type: "number" }
    }
});
 
var obj1 = new objModel(obj);
console.log(obj1.get("Fire"));
 
var dataSource = new kendo.data.DataSource({
    data: [ obj ],
    schema: {
        model: {
            id: "Id",
            fields: {
                Id: { type: "number" },
                Name: { type: "string", parse: function(e) {
                    debugger;
                    return e;
                }
            },
                Fire: { type: "date" },
                Age: { type: "number" }
            }
        }
    }
});
dataSource.read();
var obj2 = dataSource.at(0);
console.log(obj2.get("Fire"));
This make the following output to the console :
/Date(1348479856993)/
Mon Sep 24 2012 11:44:16 GMT+0200 (Romance Daylight Time)

Thanks for you help.

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Luc
Top achievements
Rank 1
Share this question
or