querytask returns no errors but undefined variables!

4020
12
Jump to solution
06-30-2015 04:42 PM
LefterisKoumis
Occasional Contributor III

This function returns undefined variable. The first alert returns: something found:1

the second alert returns "Odometer 1: undefined.

I have a very similar code shown below under GOOD CODE that it returns the expected value.

Both code execute the same querytask.

What's wrong in the first block code? Thanks.

function queryTask_odometer1_executeCompleteHandler(results)

  {

  if (results.features && results.features.length > 0) {

  alert("something found: " + results.features.length);

  resultCount=results.features.length;

  for (var i = 0; i < resultCount; i++) {

  var featureAttributes = results.features.attributes;

  for (var attr in featureAttributes) {

  if (attr = "Odometer")

  { alert(attr + "1:  " + featureAttributes[attr]);

  }

  }

  }

  }else{

  alert("nothing found");

  }

  //alert(mydata);

  }

GOOD CODE

function showResults (results) {

  var resultItems = [];

  var resultCount = results.features.length;

  alert (resultCount);

  for (var i = 0; i < resultCount; i++) {

  var featureAttributes = results.features.attributes;

  for (var attr in featureAttributes) {

  if (attr = "Odometer")

  { alert(attr + "1:  " + featureAttributes[attr]);

  resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>"); 

  }

  }

  }

       //   dom.byId("info").innerHTML = resultI

0 Kudos
12 Replies
LefterisKoumis
Occasional Contributor III

THANK YOU. I am so pissed at myself.

This is why JS needs a good IDE to capture silly mistakes like this. Oh boy, do I miss my flash builder.....

0 Kudos
BenFousek
Occasional Contributor III

There are many good editors with real time linting. I like Sublime Text - Download with SublimeLinter.

Also tasking running with Grunt: The JavaScript Task Runner

Esri has the .jshintrc (linting rules) file they use here jsapi-resources/jshint at master · Esri/jsapi-resources · GitHub

LefterisKoumis
Occasional Contributor III

Thanks. I downloaded and use webstorm. I followed instructions including uploading esrijs typescript library, but still didn't catch the case error of the script posted above.

0 Kudos