dynamic drop down of feature fields

417
0
03-19-2021 06:55 AM
Labels (3)
by Anonymous User
Not applicable

in Web AppBuilder using JavaScript I have been trying to create a drop down list  of the fields for a feature brought in through url. I have been coming up with problem at every stage, I even had problem getting just the field name - which I finally got This works great: 

var layerUrl = this.config.facilitiesURL;
var layerInfoRequest = esri.request({
   url: layerUrl,
   content: { f: "json" },
   handleAs: "json",
   callbackParamName: "callback"
});
layerInfoRequest.then(function (response) {
   fieldInfos = array.map(response.fields, function (aField) {

   return {
      fieldName: aField.name
      //visible: true
      };
 });

for (i = 0; i < fieldInfos.length; i++) {
console.log(fieldInfos[i]);
}
console.log("fieldInfos", fieldInfos[Object.keys(fieldInfos)[0]]); //obj[Object.keys(obj)[0]];
}, function (error) {
console.log("Error: ", error.message);
});

------------------------------------------------------

Now trying to fill the drop down I cannot seem to get, everything I have tried has failed this is the basic I have tried the part I am not showing is the html that points to the drop down on the configuration menu. I need help I have been working on this for a week now. I admit I am not a solid JavaScript widget developer.

var store = new Memory({       // IF I USE THIS AS THE STORE VARIABLE IT WORKS FINE
data: [
{ id: "foo", label: "Foo" },         // BUT IF I USE THE fieldInfos WHICH IS THE VARIABLE OF THE FIELDS 
{ id: "bar", label: "Bar" }           DEFINED ABOVE I GET THE ERROR: TypeError: Cannot read property 'get' of 
]                                                   undefined.    I HAVE VARIABLE fieldInfos OUTSIDE OF THE BRACKETS
});

var store = fieldInfos;
var os = new ObjectStore({ objectStore: store });

var s = new Select({
name: "test",
store: os
}, "ABCTest");
s.startup();

s.on("change", function () {
console.log("my value: ", this.get("value"))
});

0 Kudos
0 Replies