AnsweredAssumed Answered

How do I update this code for Dojo AMD?

Question asked by csergent08 Champion on May 6, 2015
Latest reply on May 12, 2015 by csergent08

I was looking at this post by Kelly Hutchins a programmatic way to populate a combo box. I have this web service: Layer: Sign (ID: 0)  and I want to populate the items from the MUTCD field; there are over 257 items in the list. How would I change this code to work as AMD and what required statements do I need; I also want the first value to be "" and display as Select One :

function init() {
  queryTask = new esri.tasks.QueryTask
  ("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/MapServer/2");

  query = new esri.tasks.Query();
  query.returnGeometry = false;
  query.outFields = ["ZONING_TYPE"];
  query.where = "ZONING_TYPE<> ''";
  queryTask.execute(query,populateList);
 }

 

 

function populateList(results) {
  //Populate the ComboBox with unique values
  var zone;
  var values = [];
  var testVals={};

  //Add option to display all zoning types to the ComboBox
  values.push({name:"ALL"})

  //Loop through the QueryTask results and populate an array
  //with the unique values
  var features = results.features;
  dojo.forEach (features, function(feature) {
  zone = feature.attributes.ZONING_TYPE;
  if (!testVals[zone]) {
  testVals[zone] = true;
  values.push({name:zone});
  }
  });
  //Create a ItemFileReadStore and use it for the
  //ComboBox's data source
  var dataItems = {
  identifier: 'name',
  label: 'name',
  items: values
  };
  var store = new dojo.data.ItemFileReadStore({data:dataItems});
  dijit.byId("mySelect").store = store;
  }
  dojo.addOnLoad(init);

Outcomes