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
Solved! Go to Solution.
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.....
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
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.