AnsweredAssumed Answered

How do I return a list of fields from FeatureLayer?

Question asked by mastayner on Apr 28, 2015
Latest reply on Apr 29, 2015 by mastayner

Seems like this should be simple, but I'm stumped.  I want to modify this sample to output to the console the list of fields for the loaded FeatureLayer.  See below.  The only modification I made was to add line 65: console.log(states);


That works fine, and shows there is attribute called "fields" for the layer states.  However, on the next line when I try  log console.log(states.fields); it says it is undefined.  Why?  And the bigger question, how do I get the list of fields?


<!DOCTYPE html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="//">
      html, body, #map {
        height: 100%; width: 100%; margin: 0; padding: 0; 

    <script src="//"></script>
      var map;



      ], function(
        Map, Extent, FeatureLayer,
        SimpleLineSymbol, SimpleFillSymbol, TextSymbol, SimpleRenderer,
      ) {
        // load the map centered on the United States
        var bbox = new Extent({"xmin": -1940058, "ymin": -814715, "xmax": 1683105, "ymax": 1446096, "spatialReference": {"wkid": 102003}});
        map = new Map("map", {
          extent: bbox

        var labelField = "STATE_NAME";

        // create a renderer for the states layer to override default symbology
        var statesColor = new Color("#666");
        var statesLine = new SimpleLineSymbol("solid", statesColor, 1.5);
        var statesSymbol = new SimpleFillSymbol("solid", statesLine, null);
        var statesRenderer = new SimpleRenderer(statesSymbol);
        // create a feature layer to show country boundaries
        var statesUrl = "";
        var states = new FeatureLayer(statesUrl, {
          id: "states",
          outFields: [labelField]

        // create a text symbol to define the style of labels
        var statesLabel = new TextSymbol().setColor(statesColor);
        var statesLabelRenderer = new SimpleRenderer(statesLabel);
        var labels = new LabelLayer({ id: "labels" });
        // tell the label layer to label the countries feature layer 
        // using the field named "admin"
        labels.addFeatureLayer(states, statesLabelRenderer, "{" + labelField + "}");
        // add the label layer to the map
    <div id="map"></div>