Select to view content in your preferred language

Fields of Feature Layer

1835
7
10-29-2010 07:56 AM
PaulSchneider
Regular Contributor
I an trying to add the fields of a feature layer to a combo box and am running into what seems like a silly simple problem.   I have created the FeatureLayer object but when I try to access the fields I get nothing.  Below is my code:


var fLayer:FeatureLayer = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/1");

if (fLayer)
{
[INDENT]var fldArr:Array = fLayer.layerDetails.fields;
Alert.show(fldArr.toString());  //....NOTHING!!....
    
/* if working... do this...
var fldAL:ArrayList = new ArrayList(fldArr);
cboField.dataProvider = fldAL;
*/[/INDENT]
}

Any thoughts?
Tags (2)
0 Kudos
7 Replies
JustinGreco
Frequent Contributor
It looks like you are trying to get the fields from a table, not a feature layer.  The layer with an index of 1 is a table, try using the layer with an index of 0 instead.

If you do want to get the fields from the table with index 1, then you need to use fLayer.tableDetails.fields instead of fLayer.layerDetails.fields.
0 Kudos
PaulSchneider
Regular Contributor
It looks like you are trying to get the fields from a table, not a feature layer.  The layer with an index of 1 is a table, try using the layer with an index of 0 instead.


Still nothing...
0 Kudos
JustinGreco
Frequent Contributor
You need to wait for the feature layer to load before you can access the fields.   So you need to add a LayerEvent.LOAD listener to fLayer. 
Also if you want to get the field names, you need to loop through each field and push the name value to the array.
0 Kudos
PaulSchneider
Regular Contributor
You need to wait for the feature layer to load before you can access the fields.   So you need to add a LayerEvent.LOAD listener to fLayer. 


That did it... thanks!!
0 Kudos
lifeEsri
Occasional Contributor
That did it... thanks!!



hello 🙂

I have the same pb when i try this Alert.show(fldArr.toString());  it's not working
'featurelayer0' .

thank you for the help
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
life Esri,

   You need to use
import mx.utils.ObjectUtil;
Alert.show(ObjectUtil.toString(fldArr));
0 Kudos
lifeEsri
Occasional Contributor
life Esri,

   You need to use
import mx.utils.ObjectUtil;
Alert.show(ObjectUtil.toString(fldArr));




thank you but still nothing ..

ok my pb is
I would like to create a combobox that listed the layers of my service in arcgis server and publish and create another combobox which contains the list of fields in each layer selected in the first combobox
and thank you in advance.
0 Kudos