Populate a ComboBox with unique values

2151
3
Jump to solution
09-26-2013 05:41 AM
by Anonymous User
Not applicable
Using the great sample found here:
http://blogs.esri.com/esri/arcgis/2009/10/07/using-javascript-to-populate-a-combobox-with-unique-val...

Following the sample to the letter and....upon clicking the ComboBox, I get the following error:
Uncaught TypeError: Object [object Object] has no method 'query'

Has anyone been able to implement this in the past year or so? I know this sample was from 2009.

Thanks!

RGibson
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Problem solved.....so if you're using the sample with the 3.x api, you must change this line:

dijit.byId("mySelect").store = store;

TO THIS

dijit.byId("mySelect").set("store",store);


rGibson

View solution in original post

0 Kudos
3 Replies
JasonZou
Occasional Contributor III
Hi Russell,

With the information provided, it's kind of hard for people to figure out what your problem is. Can you post your code and point out which line of the code causes the issue?

ESRI posted another approach here you may find it useful.
0 Kudos
by Anonymous User
Not applicable
Sorry, Jason. You bet....relevant code is below:


require([...
...
"dojo/data/ItemFileReadStore",
...


tableQueryTask = new QueryTask("http://myserver/arcgis/rest/services/MapServices/KSMap/MapServer/0");
   tableQuery = new Query();
   tableQuery.returnGeometry = false;
   tableQuery.outFields = ["EQPCAT"];
   tableQuery.where = "EQPCAT <> ''";
   tableQueryTask.execute(tableQuery, popDrop);


function popDrop(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.EQPCAT;
          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 ItemFileReadStore({data:dataItems}); 
        dijit.byId("resourceCategory").store = store;       
}


<select id="resourceCategory" data-dojo-type="dijit.form.ComboBox" onChange="app.defineResourceCategory()" style="width:150px;" ></select><br>
0 Kudos
by Anonymous User
Not applicable
Problem solved.....so if you're using the sample with the 3.x api, you must change this line:

dijit.byId("mySelect").store = store;

TO THIS

dijit.byId("mySelect").set("store",store);


rGibson
0 Kudos