About "esri/tasks/query"  's question

4204
5
Jump to solution
02-22-2015 03:57 AM
zhongrenGu
New Contributor III

my codes:

3.png

1.png

in chorom:

2.png

Now  I confused,  my god  ,what happend??

they are the same in  local/web api !

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Zhongren,

  Is there a reason that you are not using a local variable for query and queryTask in your initData function? Why would you want it to be scoped to the whole widget source by using 'this.' ? Your overall issue is a scope problem. Inside the execute block the scope of 'this' is not the same as it was before.

initData: function () {
  var query = new Query();
  query.outFields = [this.config.queryFields];
  query.outSpatialReference = this.map.spatialReference;
  query.where = this.config.queryWhere;

  var queryTask = new QueryTask(this.config.queryTaskUrl);
  queryTask.execute(query,
      lang.hitch(this, function (featureSet) {
        console.log(featureSet);
      }),
      lang.hitch(this, function (error) {
        console.log(error);
      })
  );
  .....
},

View solution in original post

0 Kudos
5 Replies
zhongrenGu
New Contributor III

Robert Scheitlin, GISPDan Patterson

thank you very much!!

0 Kudos
FilipKrál
Occasional Contributor III

Hi, not sure what's going on there but can it be because of a typo where you are creating the new QueryTask?

`this.config.qeuryTaskUrl` vs. `this.config.queryTaskUrl`, swap the 'eu'?

0 Kudos
zhongrenGu
New Contributor III

Not  this  reason, i check every words , but   thank you very much  !

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zhongren,

  Is there a reason that you are not using a local variable for query and queryTask in your initData function? Why would you want it to be scoped to the whole widget source by using 'this.' ? Your overall issue is a scope problem. Inside the execute block the scope of 'this' is not the same as it was before.

initData: function () {
  var query = new Query();
  query.outFields = [this.config.queryFields];
  query.outSpatialReference = this.map.spatialReference;
  query.where = this.config.queryWhere;

  var queryTask = new QueryTask(this.config.queryTaskUrl);
  queryTask.execute(query,
      lang.hitch(this, function (featureSet) {
        console.log(featureSet);
      }),
      lang.hitch(this, function (error) {
        console.log(error);
      })
  );
  .....
},
0 Kudos
zhongrenGu
New Contributor III

Thank you very much!    good  night!

0 Kudos