Passing additional parameters to a function within identifyResults

2494
7
Jump to solution
10-17-2012 11:03 AM
AndrewBrown1
Occasional Contributor II
First, I admit that I only have limited "hands on" experience programming with Javascript. So, I apologize for any ignorance.

I have a function that dynamically creates a DOJO table with the results of an identifyTask and a findTask. If the user performs a findTask, I want to send in a parameter to my "buildTable" function so that the map extent is changed to the extent of the findTask results. If "buildTable" is called using identifyTask, I don't want the map's extent to change to the results. This is part of my working code below:

identifyTask.execute(identifyParams, buildTable);                      }          function buildTable(queryResults){         ...do work }


findTask.execute(findParams, buildTable);


Currently, "buildTable" has no idea what function called it, whether the identifyTask or the findTask, so I'm trying to implement an additional parameter for "buildTable", a type string, identifying what method is calling it. Unfortunately, due to my limited experience using Javascript, I cannot get my following code to work. What I don't understand is: currently, "buildTable" is called without passing it a parameter (no parenthesis), so how does my parameter queryResults receive data?

identifyTask.execute(identifyParams, buildTable(queryResults,"identify"));                      }          function buildTable(queryResults, method){         ...do work and make my table from queryResults }


findTask.execute(findParams, buildTable(queryResults,"find"));


The code above obviously doesn't work, as I receive "queryResults is not defined", so how exactly can I get something like my above example to work? Or, does somebody have a better method to use so "buildTable" knows what task was used so it can do appropriate work?

Thanks,
Andrew
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor
If I understand correctly, you can also pass it what I believe is referred to as a function maker.
var _funcMaker = function(type) {   return function(queryResults) {     // do something with results based on type     // that was passed to it   }; }; findTask.execute(findParams, _funcMaker("find"));


The _funcMaker function will take any 'extra' params you want to use and return the function that processes the queryResults.

View solution in original post

0 Kudos
7 Replies
JeffPace
MVP Alum
the syntax i use is

 
var task = new esri.tasks.QueryTask(url);
task.execute(q, dojo.hitch(this, "searchCallback", linklayer, layerdesc, titleField, outfields, zoomScale, linkField));


and the callback (note this is in a widget, so the format is a little different)

searchCallback: function(layerId, layerdesc, titleField, fields, zoomScale, linkField, featureSet ) {
0 Kudos
ReneRubalcava
Frequent Contributor
If I understand correctly, you can also pass it what I believe is referred to as a function maker.
var _funcMaker = function(type) {   return function(queryResults) {     // do something with results based on type     // that was passed to it   }; }; findTask.execute(findParams, _funcMaker("find"));


The _funcMaker function will take any 'extra' params you want to use and return the function that processes the queryResults.
0 Kudos
AndrewBrown1
Occasional Contributor II
This works! Thank you very much!

If I understand correctly, you can also pass it what I believe is referred to as a function maker.
var _funcMaker = function(type) {
  return function(queryResults) {
    // do something with results based on type
    // that was passed to it
  };
};
findTask.execute(findParams, _funcMaker("find"));


The _funcMaker function will take any 'extra' params you want to use and return the function that processes the queryResults.
0 Kudos
JeffPace
MVP Alum
i like my way better, 😉 but glad you found a solution that works for you.

please mark odoe's post as the answer.
0 Kudos
AndrewBrown1
Occasional Contributor II
I don't see the "check" that is supposed to be under the "up/down vote" on the right side. I turned off adblock plus and it's still not there. How do I mark it as "answered"?
0 Kudos
JeffPace
MVP Alum
are you logged in? only the thread creator, logged in, can mark as answered
0 Kudos
AndrewBrown1
Occasional Contributor II
It doesn't show up in Chrome. Once I switched to Firefox, the big "check" showed up.
0 Kudos