feature.fields.name will not print field name

168
2
Jump to solution
03-17-2021 03:29 PM
Labels (3)
by Anonymous User
Not applicable

I am trying to setup a dropdown list of fields for a feature class. I am trying to use feature.fields.name but it keeps coming undefined, but it will tell me the amount of fields that are undefined. I can use Dojo.Json: console.log(dojoJson.toJson(featLyr.fields)); and get all the information about the fields but I cannot get just the field names. 

Anyone ever hear of this problem were the feature.fields will work but the feature.fields.name will not?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Ok I figured it out. This is what I came up with. It slightly different than I wanted to go and will get more complicated when committing to drop down in widget, but life as a programmer. 

var featLyr = this.config.facilitiesURL;
var names = [];
var layerInfoRequest = esri.request({
url: featLyr,
content: { f: "json" },
handleAs: "json",
callbackParamName: "callback"
});
layerInfoRequest.then(function (response) {
var fieldInfos = array.map(response.fields, function (aField) {
names.push(aField.name);
return {
fieldName: aField.name
};
});
for (i = 0; i < fieldInfos.length; i++) {
console.log(fieldInfos[i]);
}
}, function (error) {
console.log("Error: ", error.message);
});

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

I guess this might be be considered important to consider in trying to answer..

//featLyr is the URL of feature layer, labelField is a variable that is assigned to a field name 

featLyr = new FeatureLayer(this.svcFacilities.value, {
id: "featLyr",
outFields: [labelField]
});

var names = [];
console.log("featLyr: " + featLyr);
featLyr.on("load", function () {
for (i = 0; i < featLyr.fields.length; i++) {

//This one works fine, gives every  detail about fields
console.log(dojoJson.toJson(featLyr.fields));

//This next line should just report the field names, but reports number of fields and undefined. If run with previous console it runs not only field information, but also every bit of information in table.

console.log(featLyr.fields.name);
}
});

0 Kudos
by Anonymous User
Not applicable

Ok I figured it out. This is what I came up with. It slightly different than I wanted to go and will get more complicated when committing to drop down in widget, but life as a programmer. 

var featLyr = this.config.facilitiesURL;
var names = [];
var layerInfoRequest = esri.request({
url: featLyr,
content: { f: "json" },
handleAs: "json",
callbackParamName: "callback"
});
layerInfoRequest.then(function (response) {
var fieldInfos = array.map(response.fields, function (aField) {
names.push(aField.name);
return {
fieldName: aField.name
};
});
for (i = 0; i < fieldInfos.length; i++) {
console.log(fieldInfos[i]);
}
}, function (error) {
console.log("Error: ", error.message);
});

View solution in original post

0 Kudos