Select to view content in your preferred language

getting the attribute field value for rendering

622
2
11-01-2012 08:17 AM
LuhuaCai
Emerging Contributor
Hi, I am working on a map application that similar to the example "Calculate equal interval class breaks" . but I have difficulties of retrieving the value of the attribute field, when I use the "features[0].attributes[attributeField]" same as the example.

The field I am trying to access is named "sqldb27.SDE.afr_2010.publicSafety_e (Type: esriFieldTypeInteger, Alias: Public Safety Exp)".I suspect the problem maybe caused by the periods in my attribute filed name. However, the attribute name was generated when I joined several tables, and I am not quite sure how to get rid of the periods in there.

Any suggestions?

Thank you,

Lu
0 Kudos
2 Replies
SteveCole
Honored Contributor
Maybe try specifying the field Alias?

Whenever I accessed the attributes of results, I used the format of features[0].attributes.<the attribute Field Name>". Note the use of a period instead of array brackets ( [ ] ). Like all things Javascript, the field name WILL be case sensitive.

You could also try quoting the field name in your specification: features[0].attributes['<the attribute field name>']
0 Kudos
__Rich_
Deactivated User
Maybe try specifying the field Alias?

Off the top of my head I think you're right - the alias will be the value to use in this case "Public Safety Exp".


Whenever I accessed the attributes of results, I used the format of features[0].attributes.<the attribute Field Name>". Note the use of a period instead of array brackets ( [ ] ). Like all things Javascript, the field name WILL be case sensitive.

You could also try quoting the field name in your specification: features[0].attributes['<the attribute field name>']

Note that the dot notation won't work for attributes that have a space (or a dot I suppose!) in their name.

Safer to use square bracket notation for accessing associative arrays e.g. features[0].attributes["Public Safety Exp"]

You could stick a breakpoint in your code then peruse the attributes in a watch or you could stick some code in to log all the attribute names (and values if you like) to the console, I posted some code in another thread that will do this:

//Assumes you're using an up-to-date browser!
console.log(Object.keys(features[0].attributes));
0 Kudos