trouble populating a combo box with feature values

607
4
09-24-2012 07:11 AM
SteveCole
Frequent Contributor
In a web map I'm developing, I want a combo box populated with project names and FID so that once the user selects a project, I can zoom to that project's feature extent. Within my Init() function, I'm using a query task like this:

 //Push the attributes of the TIP Projects into the combo box
 var query = new esri.tasks.Query();    
 query.where = "1=1";
 query.outFields = ["*"];
 
 var queryTask = new esri.tasks.QueryTask("my feature layer URL");
        queryTask.execute(query,populateCbo);


Later down the line, my function "populateCbo" attempts to populate the combo box:

function populateCbo(results) {
 //Populate the dropdown list box with unique values
 var values = [];

 var features = results.features;
 dojo.forEach (features, function(feature) {
  curProject = feature.attributes.PROJECT;
  curFid = feature.attributes.FID;

  values.push({'project':curProject,'fid':curFid});
 });
 
 //Sort the values list by project name
 //values.sort(by('project'));
 
 var dataItems = {
     identifier: 'fid',
     label: 'project',
     items: values
 };
 var store = new dojo.data.ItemFileReadStore({data:dataItems});
 dijit.byId("cboTipList").store = store;
}


Everything seems to work just fine until the line which populates the store variable. The dataItems variable has information in it but after stepping through the "store = .." line, the data property for store is still null.

Am I not formatting the contents of dataItems properly? I'm not sure why it's not getting populated.

Thanks!
Steve
0 Kudos
4 Replies
derekswingley1
Frequent Contributor
Use
dijit.byId("cboTipList").set("store", store);


To specify your store for your dijit. This was a Dojo-related change that happened when we moved from 1.6 to 1.7 (this happened at JS API version 3.0).
0 Kudos
SteveCole
Frequent Contributor
Hi Derek,

I've tried that line as well with no luck. I should have mentioned that I'm specifying v2.8 of the API since I'm doing the initial development locally and not on a server. This hasn't been a problem with a dojo datagrid so I assumed it wouldn't be a problem with the combo box..
0 Kudos
derekswingley1
Frequent Contributor
I'm not sure then...can you post a repro case?
0 Kudos
SteveCole
Frequent Contributor
Derek,

Unfortunately, the feature layers being used in my map are services on our developmental server so any full code post wouldn't work for you. The good news is that I have got it working. The short story is that I believe the javascript code was fine and I was just missing a parameter on the HTML side of things.

I changed my design from a dojo combo box to a dojo FilteringSelect. After making the change, it still didn't work. After some head scratching, I modified my HTML Input tag to read
<input id="cboTipList" dojoType="dijit.form.FilteringSelect" searchAttr="PROJNAME" name="WidgetName" pageSize="12" placeHolder="Select A TIP Project" onChange="zoomRow(dijit.byId('cboTipList').value);">
and it *finally* worked. The key seems to be the "searchAttr" option, which I was originally missing. Whew!
0 Kudos