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

DataSource, Everlive, Async Fields

1 Answer 64 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Greg Galipeau
Top achievements
Rank 1
Greg Galipeau asked on 06 Jul 2015, 12:43 PM

I have a simple DataSource using Everlive as the Transport:

var gamesDataSource = new kendo.data.DataSource({
            type: 'everlive',
            schema: {
                model: activityModel
            },
            transport: {              
                typeName: 'Games'
            },  
            sort: { field: 'CreatedAt', dir: 'desc' },
            filter: { field: "UserId", operator: "eq", value: null }
        });

 

My Model is pretty simple too:

 var activityModel = {
            id: 'Id',
            fields: {
                Score: {
                    field: 'Score',
                    defaultValue: ''
                },
                Type: {
                    field: 'Type',
                    defaultValue: ''
                },              
                UserId: {
                    field: 'UserId',
                    defaultValue: null
                }              
            } 
        }; 

The intent of this is to pull back "Games" from our Everlive DataSource and bind to a listview. It works. But, I need more information from other tables and other APIs. For example: I want to put a persons current Facebook picture to associate to the user that came back. I have their Facebook Id already. However, the schema/model only seems to be able to let me put a "return" there. I can't figure out how to do asynchronous calls for a field. Ex:

  var activityModel = {
            id: 'Id',
            fields: {
                Score: {
                    field: 'Score',
                    defaultValue: ''
                },
                Type: {
                    field: 'Type',
                    defaultValue: ''
                },              
                UserId: {
                    field: 'UserId',
                    defaultValue: null
                },
                Picture: {
                    //async call to JSON to bind picture 
                }
            } 
        };

 

Anyways, I am not bound to the idea of doing an async call in the schema/model. But, I do need to find a way to do async calls as a "join" to fill in information bound to my datasource.

 

Any ideas?

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 08 Jul 2015, 02:58 PM
Hi Greg,

In this case you need to manually set the value to your viewModel that controls your view, instead of doing such operations in the model. For example, you can bind to the onInit event of your view and update the viewModel:
app.yourView = {
    onInit: function () {
        (function getPictures() {
            //do some async job and set the ViewModel's Picture property
            app.yourView.viewModel.set('Picture', somePictureUrl);
        }());
    }
};

You can find the API reference for the kendo.ui.mobile.View class at this link. In addition, I'd suggest that you take a look into this excellent blog post about the View events.

I hope this helps. Do not hesitate to write back, should you have further questions.

Regards,
George
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Greg Galipeau
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or