How to use queryTask callback function

1468
3
Jump to solution
09-27-2016 01:18 PM
LeiZhou1
Occasional Contributor

When I use queryTask to call a function, say, function showResults() as below:

queryTask.execute(query, showResults);

function showResults (results) { ….}

One thing I am confused is that: usually when a function is called, the parameter that the function is going to use (e.g., results in this case) should be included inside the showResults().  Since queryTask called this function, it should be:

 queryTask.execute(query, showResults(ABC); then this ABC will be passed into function showResults.

In the above example, there is nothing like showResults(ABC), just showResults.  How can the function showResults (results) tell what kind of parameter is actually passed into it? Thanks!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lei,

   That is because the result of a queryTask is a deferred/promise. The results are added to the resulting function based on the deferred being resolved. You may want to learn more about dojos deferred and promise classes.

https://dojotoolkit.org/documentation/tutorials/1.10/promises/ 

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Lei,

   That is because the result of a queryTask is a deferred/promise. The results are added to the resulting function based on the deferred being resolved. You may want to learn more about dojos deferred and promise classes.

https://dojotoolkit.org/documentation/tutorials/1.10/promises/ 

LeiZhou1
Occasional Contributor

Thanks a lot!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lei,

   Glad to help. Don't forget to mark this question as answered.

0 Kudos