Working with JSAPI v.3.31 on WAB DE widget stuff. So I have a query that returns a feature set, in fact it's a single feature, so that:..
var resultFeatures = featureSet.features;
var graphic = resultFeatures[0];
. Then I provide some styling and add it to the map
var symbol = new SimpleFillSymbol();
symbol.setColor(new Color([255,0,51,0.5]));
graphic.setSymbol(symbol);
this.map.graphics.add(graphic);
I can access the attributes of the feature using:
var attributes = graphic.attributes
But I can't figure out how to step through them, to selectively add them to an InfoTemplate or otherwise process the attribute info. All of the below has failed because attributes is type Object..
attributes.forEach( function()...)
// or
dojo.forEach(attribute,function()...)
// or
array.forEach(attribute,function()...)
What's the solution here? I don't want to have to access each attribute directly:
grahic.attributes['myattribute']
THANKS!
Solved! Go to Solution.
Arne,
The issue you are having is that you are trying to treat the graphic.attributes as an array when it is an Object
https://developers.arcgis.com/javascript/3/jsapi/graphic-amd.html#attributes
To loop through the object you can use Object.entries
Arne,
The issue you are having is that you are trying to treat the graphic.attributes as an array when it is an Object
https://developers.arcgis.com/javascript/3/jsapi/graphic-amd.html#attributes
To loop through the object you can use Object.entries
Sweet, worked like a charm! Plus, the syntax isn't as gross as some I've seen. Haha. Reminds of stepping through k,v n Python dict items. - I'll have another questions for you in a separate thread this afternoon.