AnsweredAssumed Answered

querytask returns no errors but undefined variables!

Question asked by lkoumis on Jun 30, 2015
Latest reply on Jul 1, 2015 by lkoumis

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[i].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[i].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

Outcomes