I have a module with four functions that call one after another. I am trying to execute a popup module template. One of the functions is open, the rest are private. This happens as follows:
publicMethod called from another modulequeryNames called from publicMethodexecute(parameters, callback?, errback?) called from queryNamesaddNamesList invoked as an argument callback? execute- Multiple created
dijit/form/CheckBoxand method startedquerySegments onChange querySegmentsyou must call the method of the object created in publicMethod.
The problem is in step 6, I can not reach the object created in step 1.
I tried using dojo hitch to determine the argument callback?in step 3, but I can't get it to work. I tried to put thisin my first argument, but even then I cannot reach the required area for the call addNamesList.
Here are some examples to demonstrate this problem.
define([
'dojo/dom',
'dijit/form/CheckBox',
'esri/layers/ArcGISDynamicMapServiceLayer',
'esri/tasks/query',
'esri/tasks/QueryTask',
'dojo/_base/lang'
],
function (
dom,
CheckBox,
ArcGISDynamicMapServiceLayer,
Query, QueryTask,
lang
) {
var queryNames = function (map, mapLayer) {
var queryTask = new QueryTask("url")
var query = new Query()
queryTask.execute(query, lang.hitch(map, "addNamesList", mapLayer), function(error) {console.log(error)})
}
var addNamesList = function (mapLayer, featureSet) {
console.log('addOplist')
var namesCount = featureSet.features.length
for (var i = 0; i <namesCount; i++) {
var cbox = new CheckBox({
id: "cbox_" + i,
value: featureSet.features[i].attributes["someID"],
checked: false,
onChange: function (evt) {
querySegments(this.value, mapLayer)
}
})
cbox.placeAt("someDiv" + i, "first")
}
}
var querySegments = function (name, mapLayer) {
var queryStatement = "someID = " + name
var layerDefinitions = [queryStatement]
mapLayer.setLayerDefinitions(layerDefinitions)
}
var publicMethod = function (map) {
var mapLayer = new ArcGISDynamicMapServiceLayer('restURL')
map.addLayer(mapServiceLayer)
queryNames(map, mapLayer)
return mapLayer
}
return {
publicMethod: publicMethod
}
}
)
You can see a more detailed explanation and a working example on this other (and wider) question that I posted in Code Review.
I'm new to JavaScript, and I think I still have a lot of problems viewing, closing, and callbacks.
I will be deeply grateful for any contribution, including how to improve this issue.
Edit
( dojo hitch) . addNamesList ( errback, , ). , , addNamesList map (hitch first argument). this , .
, :
var queryNames = function (map, mapLayer) {
...
queryTask.execute(query, addNamesList)
}
var addNamesList = function (featureSet) {
...
...
...
querySegments(this.value, mapLayer)
}
mapLayer , . Uncaught ReferenceError: mapLayer is not defined. .