xupla

QueryTask.execute in a Dojo class

Discussion created by xupla on Mar 27, 2014
Latest reply on Mar 27, 2014 by btfou
I have written a class with a method which returns the coordinates of a point.

define(["dojo/_base/declare", "esri/tasks/QueryTask", "esri/tasks/query", "dojo/dom"],

    function (declare, QueryTask, Query, dom) {
        return declare(null, {

            meterId: null,
            featureUrl: null,
            queryString: null,

            constructor: function (options) {
                this.featureUrl = options.featureUrl;
                this.meterId = options.meterId;
                this.queryString = options.queryString;
            },

            doFind: function () {
                var meterCoor = "";
                var query = new Query();
                var queryTask = new QueryTask(this.featureUrl);
                query.where = this.queryString + " = '" + this.meterId + "'";
                query.returnGeometry = true;
                query.outFields = ["*"];

                queryTask.execute(query, function (results) {
                    for (var x = 0; x < results.features.length; x++) {
                        meterCoor = results.features[x].geometry.x + "," + results.features[x].geometry.y;
                    }
                });
                
                return meterCoor;
            }
        });
    });


My problem is that "meterCoor" is being populated, but when I'm returning it the variable is left empty. I can't figure out what is wrong with my code. I'll appreciate any help given to me.

Outcomes