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

schema.parse asynchronous execution

1 Answer 160 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
pixi
Top achievements
Rank 1
pixi asked on 22 Sep 2015, 10:02 AM

Hello!

First of all I'm using Kendo UI with AngularJS.

I use schema.parse function to reprocess the results. However, the issue I've is that in parse function I manually overwrite some columns ​with a call from a angular service, which returns promise. The columns which are overwritten via promise are not defined. You can easily imagine that via this example:

- I define two fields: code: {type: 'number'}, name: {type: 'string'}

- Via API call only code is obtained (name is undefined)

- in parse function I call a service which obtains me name (code parameter is passed into it).

 

Example of parse function:

parse: function(data) {
    //data.name = 'test'; // THIS WORKS
    service.call(data.code).then(function(result){
            data.name = result; //DOESN'T WORK
    });
    return data;
}

 

Any possibility to achieve the wanted behaviour? Or some other option to be sure that dependant data can be provided manually (so not via API)?

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Sep 2015, 08:55 AM

Hello pixi,

I'm afraid that this will not work. The parse function is synchronous, thus when the asynchronous call completes the execution of the parse function has already completed. The data from the parse function is used to construct the ObservableObject instances returned by the DataSource. Thus, modifying the original data at later stage (which is what happens in the code snippet) will not have effect on the DataSource data.

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