AnsweredAssumed Answered

Populate dropdown, specifying label and values coming from different attributes

Question asked by schlot on Sep 25, 2013
Latest reply on Sep 30, 2013 by schlot
I have a layer of school districts that contains both the school district name and a district ID number.  I have a layer of schools which contains just the district ID number.

I'm populating my dijit.form.Select from the attributes of the school district layer.  I need the list to appear as district names, but at the same time, it would be nice if the values were the district IDs.  Then I could fire off a query on the school layer using a where clause without having to do any other hoop jumping (I think).  This code works to populate my dropdown, I'd just like it to be a little more functional. 

function populateDropDownList(){     var queryTask = new QueryTask(educationLayer.url + "/3");     var query = new Query();     query.outFields = ["DIST_NAME"];     query.where = "1=1";     query.returnGeometry = false;       queryTask.on('complete', resultsHandler);     queryTask.on('error', errorHandler);     queryTask.execute(query); }  function resultsHandler(results){     select = registry.byId("distSelect");// a dijit.form.Select      districtList.length = 0;     var numResults = results.featureSet.features.length;     for (var j = 0; j < numResults; j++) {         var distName = results.featureSet.features[j].attributes.DIST_NAME; //note the attribute name for the district code is DIST_CODE         districtList.push(distName);     }     districtList.sort();     var testList = arrayUtil.map(districtList, function (item, index){     return {         label:item,         value:item         };     });     select.addOption(testList); }

Outcomes