add attribute to Graphic attributes

6128
6
Jump to solution
11-18-2015 02:46 PM
DaveOrlando
Occasional Contributor III

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?

0 Kudos
1 Solution

Accepted Solutions
FilipKrál
Occasional Contributor III

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.

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
DaveOrlando
Occasional Contributor III

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

0 Kudos
FilipKrál
Occasional Contributor III

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.

DaveOrlando
Occasional Contributor III

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.

0 Kudos
DaveOrlando
Occasional Contributor III

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";
AlexOliinyk
New Contributor

do you have real working demo ? I trying  a lot of difference examples no one doesn't work for me (

0 Kudos