require(["esri/layers/support/Field"], function(Field) { /* code goes here */ });
Class: esri/layers/support/Field
Inheritance: Field Accessor
Since: ArcGIS API for JavaScript 4.0

Information about each field in a layer. Field objects must be constructed when creating a FeatureLayer from client-side graphics. This class allows you to define the schema of each field in the FeatureLayer. Note that you do not need to add fields to the constructor of a FeatureLayer loaded from a service since they are already defined by the service. See the sample below for more information about using this module.

See also:
Example:
// Each object in this array is autocast as
// an instance of esri/layers/support/Field
var fields = [
  {
    name: "ObjectID",
    alias: "ObjectID",
    type: "oid"
  }, {
    name: "title",
    alias: "title",
    type: "string"
  }, {
    name: "type",
    alias: "type",
    type: "string"
  }, {
    name: "mag",
    alias: "Magnitude",
    type: "double"
}];

// add the array of fields to a feature layer
// created from client-side graphics
featureLayer.set({
  fields: fields,
  objectIdField: "ObjectID"
});

Constructors

new Field(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String

The display name for the field.

more details
more detailsField
String

The name of the class.

more details
more detailsAccessor
Number|String|null|undefined

The default value set for the field.

more details
more detailsField
String

Contains information describing the purpose of each field.

more details
more detailsField
Domain

The domain associated with the field.

more details
more detailsField
Boolean

Indicates whether the field is editable.

more details
more detailsField
Number

The field length.

more details
more detailsField
String

The name of the field.

more details
more detailsField
Boolean

Indicates if the field can accept null values.

more details
more detailsField
String

The data type of the field.

more details
more detailsField
String

The types of values that can be assigned to a field.

more details
more detailsField

Property Details

alias String

The display name for the field.

Default Value:null
declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

Since: ArcGIS API for JavaScript 4.9

The default value set for the field.

Default Value:undefined
description String
Since: ArcGIS API for JavaScript 4.12

Contains information describing the purpose of each field.

See also:
domain Domain

The domain associated with the field. Domains are used to constrain the values allowed in a field. There are two types of domains: RangeDomain and CodedValueDomain.

Default Value:null
Example:
// print out the coded domain values when the layer is loaded
view.whenLayerView(featureLayer).then(function(layerView) {
  layerView.watch("updating", function(value) {
    if (!value) {
      featureLayer.fields.forEach(function(field){
        if (field.domain){
          var domain = field.domain
          console.log(field.name, domain.type, domain.name);
          if (domain.type === "coded-value"){
            domain.codedValues.forEach(function(codeValue){
              console.log("name:", codeValue.name, "code:", codeValue.code);
            });
          }
        }
      });
    }
  });
});
editable Boolean

Indicates whether the field is editable.

Default Value:true
length Number

The field length.

Default Value:-1
name String

The name of the field.

Default Value:null
nullable Boolean

Indicates if the field can accept null values. Requires ArcGIS Server version 10.1 or greater.

Default Value:true
type String

The data type of the field.

Possible Values:"small-integer"|"integer"|"single"|"double"|"long"|"string"|"date"|"oid"|"geometry"|"blob"|"raster"|"guid"|"global-id"|"xml"

Default Value:null
valueType String
Since: ArcGIS API for JavaScript 4.12

The types of values that can be assigned to a field. See the table below for a list of possible values.

ModeDescription
name-or-titleText that represents a name, title, label, or keyword for each feature.
descriptionText that provides a longer description of the feature, more than just a name or title.
type-or-categoryTypes or categories that group features based on common characteristics.
count-or-amountIntegers (no decimal) that represent how many or how much there is of a specific attribute.
percentage-or-ratioNumber values in this field reflect the relationship between different quantities.
measurementA number that reflects a characteristic that you can precisely measure.
unique-identifierThe values in this field are used to positively distinguish one feature or entity from another.
ordered-or-rankedThe values in this field represent a feature's status in an ordered or ranked list. For example, a feature could be one of the following: Small, medium, large, First, second, third, fourth, or Informational, warning, error, failure.
binaryOnly one of two values are possible for each feature. Some examples include the following: On or off, Yes or no, True or false, or Inhabited or vacant.
location-or-place-nameValues in this field represent a geographic location. Examples of values in such a field include a street address, city name, region, building name (such as A.K. Smiley Public Library), attraction name (such as Alameda County Fairgrounds or Cairngorms National Park), postal code, or country.
coordinateThese fields store a geographic coordinate value such as x, y, z, latitude, or longitude.
date-and-timeValues in this field store explicit dates and times or date references such as days of the week, months, or years.
noneNo specified type.

Possible Values:"binary"|"coordinate"|"count-or-amount"|"date-and-time"|"description"|"location-or-place-name"|"measurement"|"name-or-title"|"none"|"ordered-or-ranked"|"percentage-or-ratio"|"type-or-category"|"unique-identifier"

See also:

Method Overview

NameReturn TypeSummaryClass
*

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform.

more details
more detailsField
Object

Converts an instance of this class to its ArcGIS portal JSON representation.

more details
more detailsField

Method Details

fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from a product in the ArcGIS platform. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter:
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns:
TypeDescription
*Returns a new instance of this class.
toJSON(){Object}

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() topic in the Guide for more information.

Returns:
TypeDescription
ObjectThe ArcGIS portal JSON representation of an instance of this class.

API Reference search results

NameTypeModule
Loading...