Select to view content in your preferred language

Obtaining individual field alias from query resutls

900
2
Jump to solution
09-26-2013 09:22 AM
by Anonymous User
Not applicable
Trying to obtain an individual field alias from results returned from a query. I can see the list of field aliases for an object (in the "results" object) but not sure how to get the individual alias value for a field. Hope that makes sense. Code is below....where "att" is the variable containing the actual field name. In this case the feature has three fields which are aliased. I know I could set up a switch to evaluate the value of the "att" variable but there exists the potential to have as many as 50 fields.

function showQueryResults(results) {
       dom.byId("facilityDetailDiv").innerHTML = "";
          var s = "";
          for (var i=0, il=results.features.length; i<il; i++) {      
            var featureAttributes = results.features.attributes;
            for (att in featureAttributes) {     
              s = s + "<b>" + att + ":" + featureAttributes[att] + "<br>";
            }
            s = s + "<br>";
          }        
    dom.byId("facilityDetailDiv").innerHTML = s;  
        }
0 Kudos
1 Solution

Accepted Solutions
MattLane
Frequent Contributor
Why don't you do something like
function showQueryResults(results) {   dom.byId("facilityDetailDiv").innerHTML = "";   var s = "", aliases = results.fieldAliases;   for (var i=0, il=results.features.length; i<il; i++) {      var featureAttributes = results.features.attributes;     for (att in featureAttributes) {        s = s + "<b>" + (aliases.hasOwnProperty(att) && aliases[att]) + ":" + featureAttributes[att] + "<br>";     }     s = s + "<br>";   }    dom.byId("facilityDetailDiv").innerHTML = s;  }


The hasOwnProperty method just safeguards that you don't try to retrieve a value for a non-existent key.

View solution in original post

0 Kudos
2 Replies
MattLane
Frequent Contributor
Why don't you do something like
function showQueryResults(results) {   dom.byId("facilityDetailDiv").innerHTML = "";   var s = "", aliases = results.fieldAliases;   for (var i=0, il=results.features.length; i<il; i++) {      var featureAttributes = results.features.attributes;     for (att in featureAttributes) {        s = s + "<b>" + (aliases.hasOwnProperty(att) && aliases[att]) + ":" + featureAttributes[att] + "<br>";     }     s = s + "<br>";   }    dom.byId("facilityDetailDiv").innerHTML = s;  }


The hasOwnProperty method just safeguards that you don't try to retrieve a value for a non-existent key.
0 Kudos
by Anonymous User
Not applicable
Perfect, Matt. Thanks a million.
0 Kudos