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

Encapsulating a dataSource.fetch()

1 Answer 147 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 01 Jun 2013, 07:40 AM
Hello Support:

I'm having conceptual difficulties with how to encapsulate a fetch().  Consider the following:

var getAllProjects = function() {
            projectsDataSource.fetch(function()  {
                var dataView = projectsDataSource.view();
                return dataView;
            });
        };

where projectsDataSource is a Kendo dataSource defined with a remote source.  I should say that the inner portion above works flawlessly (by inner portion I mean the part defined as projectsDataSource.fetch(function() { ...}).

However, I decided to encapsulate this functionality in a separate module defined by RequireJS, leading naively to the code above where I declare getAllProjects().

I'm trying to return dataView to the outer function, getAllProjects(), a function that is revealed publicly.  All I get back, though, is undefined.  It would seem that you're using callbacks, not promises, which appears to be confusing me.

What am I missing here?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Jun 2013, 01:53 PM
Hi,

 The fetch method accepts a function which is invoked when the data source finishes loading data. Also the fetch method doesn't return a value. I am afraid that your code isn't going to work like this. You need to take into account that fetch is asynchronous.

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
Data Source
Asked by
Eric
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or