DataSource, Everlive, Async Fields

2 posts, 0 answers
  1. Greg Galipeau
    Greg Galipeau avatar
    13 posts
    Member since:
    Jul 2009

    Posted 06 Jul 2015 Link to this post

    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?

  2. George
    Admin
    George avatar
    500 posts

    Posted 08 Jul 2015 Link to this post

    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.
     
Back to Top