Select to view content in your preferred language

append records to the results of findtask.execute

1379
8
11-03-2010 05:30 AM
by Anonymous User
Not applicable
I would like to populate a �??results�?? array from a findtask.execute function with additional items.

Essentially create a loop �??

Function getParcel(queryArray) {
var i=0
var results = new array();
for (i=0;i<=5;i++)
{
findParams.searchText = queryArray;
results =   findTask.execute(findParams);
}
}

Now results, is an array of type FindResult, and it says it can�??t be constructed -

http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi_start.htm

So my �??var results = new array();�?? surely must not be right.  But there must be a way to append additional info into this result set?

Or, what would be great is if I could just set findParams.searchText to an array or delimeted text and it could search on all inputs.
0 Kudos
8 Replies
timgogl
Deactivated User
you might try it a different way....

var arResults = new array();

Function getParcel(queryArray) {
  var i=0

  for (i=0;i<=5;i++)
  {
    findParams.searchText = queryArray;
    findTask.execute(findParams,taskCallBack);
  }
}

function taskCallBack(taskResults){
  arResults.push(taskResults);
}


your results array would be global, when the task completes the taskResults are sent to the callback function and the taskResults and pushed into the next spot in the global results array.

one of your possible issues is that no matter how fast your task call is, it likely doesnt return a value from the first execute before the loop is finished looping. so results may be unexpected.
0 Kudos
by Anonymous User
Not applicable
That's strange.  lowgas, that code creates a two dimensional array. the 'returned' objects are in the second level 0,0 0,1 and 0,2
This is my exact code -

    var arResults = new Array();
    var queryArray = new Array();
    queryArray[0] = '2211-1820-28-034';
    queryArray[1] = '2211-1820-28-033';
    queryArray[2] = '2211-1820-28-032';

    function getParcel(queryArray) {
        var i = 0

        for (i = 0; i <= 2; i++) {
            findParams.searchText = queryArray;
            findTask.execute(findParams, taskCallBack);
        }
   }

function taskCallBack(taskResults){
    arResults.push(taskResults);
}

Very odd.
0 Kudos
by Anonymous User
Not applicable
actually, the second level is 0,0 1,0 2,0
0 Kudos
by Anonymous User
Not applicable
Yeah, that looks like it would work, low gas, but it's acting very, very weird.  I think you are right that -

"one of your possible issues is that no matter how fast your task call is, it likely doesnt return a value from the first execute before the loop is finished looping. so results may be unexpected."
0 Kudos
timgogl
Deactivated User
hrm... well i'm not too certain about the map stuff yet. i have worked with maps on the web for about 6 weeks, and esri maps for about 3/4 weeks. i still have lots to learn.


what exactly do you want stored in the array? what my example was pushing into your array was the FindResults object. which may or may not have everything (anything) you actually want to use in your array.


well using the call back function should help with the loop. with the callback function, even though the loop will iterate quickly (much quicker then the find can execute), the call back will be executed each time the find execute is completed. so even though the loop is long done running, the find is still happening, and when its done will execute the call back.....

heh... i may not have written that very clearly.

i do NOT know if some of your finds will complete before others... in other words, i dont know if the execute for the first item will complete first and the second, second etc. so whether your array of results is in the same order as the array that you queried from, you will need to check and find out.
0 Kudos
by Anonymous User
Not applicable
Yes, the FindResults is exactly what I want.  I would like the results to contain multiple objects that can be turned into graphics and displayed.  I know that can be done, because a 'contains' type search works just fine.  What I'm looking for is multiple unique queries in one results set.

Anyway, It was very weird when I stepped through it.  The 'for' would go through ALL it's iterations before the taskCallBack function was called.  Not sure how it managed to do that.

Thanks for any ideas.
0 Kudos
timgogl
Deactivated User
because the for loop only takes like a nano second to finish, where each execute would take a milisecond or so to fetch the info and return a resultset. so each time a result set was returned from the execute the call back function would then trigger and the given resultset would be added to your array.
0 Kudos
by Anonymous User
Not applicable
I did get this to work by the way.  I modified the CallBack function to 'flatten' the two dimensional array that got created into a one dimensional array.

   var arResults = new Array();
   var arResultsFlatten = new Array;
   var resultCounter = 0;
   function taskCallBack(taskResults){
    var i = 0;
    arResults.push(taskResults);

    resultCounter = resultCounter + 1
    if (resultCounter == queryArray.length) {
        var i = 0;
        var j = 0;
        var k = 0;
        // turn the 2 dimensional array into a one dimensional array.
        for (i = 0; i <= queryArray.length - 1; i++) {
            for (j = 0; j <= arResults.length - 1; j++) {
                arResultsFlatten = arResults;
                test3 = arResultsFlatten[0];
                k = k + 1;
            }
          }
        showMultiResults(arResultsFlatten);
        }
      }


-- Thanks again.
0 Kudos