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.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); }
Solved! Go to Solution.
function populateDropDownList(){ var queryTask = new QueryTask(educationLayer.url + "/3"); var query = new Query(); query.outFields = ["DIST_NAME", "DIST_CODE"]; // assuming DIST_CODE is the field for district id 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.attributes.DIST_NAME; var distID = results.featureSet.features .attributes.DIST_CODE; districtList.push({label: distName, value: distID}); } districtList.sort(function(item1, item2) { var label1 = item1.label.toLowerCase(), label2 = item2.label.toLowerCase(); return (label1 > label2) ? 1 : (label1 < label2) ? -1 : 0; }); select.addOption(districtList); }
function populateDropDownList(){ var queryTask = new QueryTask(educationLayer.url + "/3"); var query = new Query(); query.outFields = ["DIST_NAME", "DIST_CODE"]; // assuming DIST_CODE is the field for district id 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.attributes.DIST_NAME; var distID = results.featureSet.features .attributes.DIST_CODE; districtList.push({label: distName, value: distID}); } districtList.sort(function(item1, item2) { var label1 = item1.label.toLowerCase(), label2 = item2.label.toLowerCase(); return (label1 > label2) ? 1 : (label1 < label2) ? -1 : 0; }); select.addOption(districtList); }
new FilteringSelect({ placeHolder: "Sort Results", value: null, placeHolder: "Select a Value", store: new Memory({ data: results.featureSet.features, idProperty: "DIST_CODE" }), labelAttr: "DIST_NAME", searchAttr: "DIST_NAME" });
function resultsHandler(results){ var select = registry.byId("distSelect");//my filteringSelect dijit districtList.length = 0; var numResults = results.featureSet.features.length; for (var j = 0; j < numResults; j++) { var distName = results.featureSet.features.attributes.DIST_NAME; var distCode = results.featureSet.features .attributes.DIST_CODE; districtList.push({label: distName, value: distCode}); } districtList.sort(function(item1, item2) { var label1 = item1.label.toLowerCase(), label2 = item2.label.toLowerCase(); return (label1 > label2) ? 1 : (label1 < label2) ? -1 : 0; }); var dataStore = new Memory({data:districtList}); select.set ("store", dataStore); // select.addOption(districtList); }
var dataStore = new Memory({data:districtList, idProperty:"value"});