Select to view content in your preferred language

inconsistent Behavior this morning with the Deferred object

3848
1
02-05-2015 07:19 AM
MarkAndrews
Deactivated User

A while back I wrote a function with a deferred object that has been working successfully for several months.

This morning, it fails and I am not sure why.

I am using the 3.11 ESRI Javascript Library:

Here is the function call with the deferred object (it is in a helper class, so it can be called over mulitple pages):

addTract: function () {

           

            var d = new Deferred();

            var layer = new FeatureLayer(tractFeatureurl, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] });

            layer.setDefinitionExpression("tract_id = " + this.tractid);

            this.mapObj.map.addLayer(layer);

            this.tracts = layer;

            var q = new Query();           

            q.returnGeometry = true;

            q.outFields = ["*"];           

            var cb = layer.queryFeatures(q);

           

            cb.then(lang.hitch(this, function (results) {               

                this.tractFeature = results.features[0];

                console.debug(this.tractFeature);

                this.mapObj.zoomToFeatures(results.features);

                d.resolve(this.tractFeature);

                return d.promise;

            }));

           

    }

It is being class on a page like this:

var res = utils.addTract();

console.debug(res);

          if (res == undefined) {

              alert("undefined");

              return;

          }

          res.then(function (tract) {

                    // do more processing....

          });

Up until this morning, it was working fine, but now the response back from the addTract function is undefined.

Tags (1)
0 Kudos
1 Reply
JohnGrayson
Esri Regular Contributor

The following line should be outside if the async 'then' function.

return d.promise;

John

0 Kudos