Avoid hardcoding column name on result?

345
1
02-05-2011 05:15 AM
GlenReid
New Contributor II
On a query result, is there a way to avoid having to use the actual column name? I have the desired column in a variable (displayColumn) which changes based on user selections.  My query.outFields works fine, but I can't get the results using the variable:

query.outFields = ["ID", "STATE", displayColumn];

for (var i=0; i<numFeatures; i++) {
   var graphic = fset.features;
   var attr = fset.features.attributes;

   // works: console.log("name: " + attr.NAME;
   // fails: console.log("name: " + attr.displayColumn;
...


Thanks,
Glen
0 Kudos
1 Reply
derekswingley1
Frequent Contributor
Use:
console.log("name: " + attr[displayName]);


Your example code that fails is looking for a property named "displayName" on the attr object. The syntax I used lets you specify a property name as a string.
0 Kudos