If you use a query task, you get field aliases back with your query result.
If you're stuck using identify, can you specify your user-friendly names in your info template? Otherwise, I think you're going to have to send off an additional request to get the layer info from the map service, build a field_name: field_alias object and then use the aliases in your info window content. I don't see a way to access field aliases from an identify result. Maybe someone else knows...
<!DOCTYPE html"> <html> <head> <script type="text/javascript">var djConfig = {parseOnLoad: true};</script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"></script> <script type="text/javascript"> dojo.require("esri.map"); var field_obj = {}; function init() { var layer_url = 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hurricanes/NOAA_Tracks_1851_2007/MapServer/0' esri.request({ url: layer_url, content: { f: 'json' }, callbackParamName: 'callback', load: function(response, io) { var fields = response.fields; dojo.byId('fields').innerHTML = ''; dojo.forEach(fields, function(field) { dojo.byId('fields').innerHTML += 'Name: ' + field.name + '; Alias: ' + field.alias + '<br />'; field_obj[field.name] = field.alias; }); }, error: function(error) { console.log('error: ', error); } }); } dojo.addOnLoad(init); </script> </head> <body> <div id="fields">field names and aliases will show up here.</div> </body> </html>
function addToMap(idResults, evt) { var strContent=""; for(var i in idResults){ if(idResults.layerId===2||idResults.layerId===3) { //Header strContent += "<label style='font-size:14px; text-decoration:underline;'>"+idResults.layerName+"</label> <br/>"; //Attributes switch(idResults.layerId){ case 2: strContent += " -- <a href=\"" + idResults.feature.attributes.LANDUSE + "\"target=\"_blank\" >Land Use: " + idResults.feature.attributes.LANDUSE + "</a><br/>"; break; case 3: strContent += " -- <a href=\"" + idResults.feature.attributes.Shape + "\"target=\"_blank\" >Shape: " + idResults.feature.attributes.Shape + "</a><br/>"; break; } } } if (strContent == '') { document.getElementById('divMiniResults').innerHTML = 'No Data at this location. <br/><br/>'; } else { document.getElementById('divMiniResults').innerHTML = strContent; } }
function addToMap(idResults, evt) { var contentArray= new Array(); var resultLayerId; //var strContent=""; for (var i in idResults){ resultLayerId = idResults.layerId; idResults.feature.setInfoTemplate(new esri.InfoTemplate("", "${*}")); if (contentArray[resultLayerId] === undefined) { // write heading for that layer contentArray[resultLayerId] = "<label style='font-size:14px; text-decoration:underline;'>"+idResults.layerName+"</label> <br/>"; // write record result contentArray[resultLayerId] += idResults.feature.getContent(); } else { // Heading already written. Append feature details contentArray[resultLayerId] += idResults.feature.getContent(); } } if (contentArray.length === 0) { document.getElementById('divMiniResults').innerHTML = 'No Data at this location. <br/><br/>'; } else { document.getElementById('divMiniResults').innerHTML = contentArray.join('<br />'); } }