Graphic | API Reference | ArcGIS API for JavaScript
var feature = new Graphic(results, symbol, inPoints.attributes); feature.attr("new_att", "new_value");
I would like to add an attribute to the existing attributes.
Is this not the intended syntax or use of the method?
Solved! Go to Solution.
Hi,
What do you mean by "attribute"?
The attr(name, value) method adds an attribute to the DOM node of the graphic, not to the graphic feature.
So setting feature.attr('something', 123) will result in the graphic dom node to be:
<path something="123" ...></path>
(although I am not sure what types of elements graphics are).
In order to add an attribute to the graphic feature, in the sense of adding a new field, use the setAttributes method.
Filip.
Dave,
Is the results array that you have an array of geometries or graphics? That is the only thing I can see in your code that leads to questioning.
the 'results' are from a geometryService.intersect so just geometries. The 'inPoints' are the original graphics which I use to marry the attributes back to the results
Hi,
What do you mean by "attribute"?
The attr(name, value) method adds an attribute to the DOM node of the graphic, not to the graphic feature.
So setting feature.attr('something', 123) will result in the graphic dom node to be:
<path something="123" ...></path>
(although I am not sure what types of elements graphics are).
In order to add an attribute to the graphic feature, in the sense of adding a new field, use the setAttributes method.
Filip.
Thanks,
yes, I was trying to add to an existing attribute stack. I got it working with this.
atts = inPoints.attributes; atts["new_att"] = "new_value"; var feature = new Graphic(results, symbol); feature.setAttributes(atts);
thanks again.
or... back to my original code at top, I just realized you can add a new attribute directly using...
var feature = new Graphic(results, symbol, inPoints.attributes); feature.attributes["new_att"] = "new_value";
do you have real working demo ? I trying a lot of difference examples no one doesn't work for me (