Select to view content in your preferred language

Query Loop

1218
3
02-28-2012 08:27 AM
demdeberanz
Emerging Contributor
Hi everybody,
    I need to run a loop inside where I run some query (queryTask.execute(...)) on a Feature Layer.
As you know, queries run in rapid sequence may terminate in different order then the original. A possible solution I found is to use a callback function that add the results (everytime is called) to a global array and at the end we can find those results in that array. But at this point I get an issue, I don't know exactly when all the queries are terminated, so I can't actually use the queries' results.
I tried to use dojo.connect(...) to connect the onComplete event of every query run to the function that add the results to the global array but this doesn't work properly and furthermore I still don't know when exactly all the queries terminate.

Have you got any idea?have someone ever got this issue?

Thank you everybody.
0 Kudos
3 Replies
derekswingley1
Deactivated User
We have a sample showing how to handle the results from multiple query tasks:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/query_deferred_list.html

If you need to run multiple queries, manage them with a deferredList.
0 Kudos
demdeberanz
Emerging Contributor
We have a sample showing how to handle the results from multiple query tasks:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/query_deferred_list.html

If you need to run multiple queries, manage them with a deferredList.


Thank you for your help!:) this solution works properly! But now I've got another issue, I need to associate to each query an id that depends on a variable.
How can I do this? (at the beginning I used dojo.hitch function to pass other than the results also this id  ex.: queryTask.execute(query,dojo.hitch(...)) )

Thank you very much.
0 Kudos
StevenGriffith
Deactivated User
Here's how to do this. You need to create a closure to capture the actual query identifier; but since closures are not created until they function whose data they represent is actually executed, you need to create and call an inline function:


                    // function is executed immediately and passed the value of i, which creates
                    // the closure *during* loop evaluation so the value of i is different for each closure.
                    (function (value) {
                        qt.execute(q)
                            .then(function (featureset) {
                                processReturn(featureset, i);
                            });
                    })(i);

where i is my array index variable from the 'for' loop.

Steve G.
0 Kudos