Simple ComboBox and queryTask - Not getting desired results

3952
2
Jump to solution
02-03-2015 12:04 PM
KeithAnderson
New Contributor III

Friends

Edit fiddle - JSFiddle

jsFiddle link above is simple but I cannot get any field to populate other than OBJECTID.

Initially trying to return distinct values from map service, which works in the REST interface, but not for me in code.

Any suggestions welcome.

Thanks

Keith

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor


The code in this sample a little old, as I think ItemFileReadStore is deprecated, but I was able to get it to work by removing the "identifier" in your data. I think the "identifier" has to a numeric field... I think.

This worked for me

var query = new esri.tasks.Query();
query.where = "1=1";
query.returnGeometry = false;
query.returnDistinctValues = true;
query.outfields = ["FIELD_NAME"];
//query.orderByFields = ["FIELD_NAME"]; // only works in 10.1 services, this one is 10.01
getList.queryFeatures(query, function (featureSet) {
    //Populate dropdown list 
    var values = dojo.map(featureSet.features, function (feature) {
        return {
            name: feature.attributes.FIELD_NAME
        };
    });
    var dataItems = {
        label: 'name',
        items: values
    };
    var store = new dojo.data.ItemFileReadStore({
        data: dataItems
    });
    ...

That populated the dropdown with the field names.

Here is the docs on Combox with samples using the dojo/store to populate the dropdown.

View solution in original post

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor


The code in this sample a little old, as I think ItemFileReadStore is deprecated, but I was able to get it to work by removing the "identifier" in your data. I think the "identifier" has to a numeric field... I think.

This worked for me

var query = new esri.tasks.Query();
query.where = "1=1";
query.returnGeometry = false;
query.returnDistinctValues = true;
query.outfields = ["FIELD_NAME"];
//query.orderByFields = ["FIELD_NAME"]; // only works in 10.1 services, this one is 10.01
getList.queryFeatures(query, function (featureSet) {
    //Populate dropdown list 
    var values = dojo.map(featureSet.features, function (feature) {
        return {
            name: feature.attributes.FIELD_NAME
        };
    });
    var dataItems = {
        label: 'name',
        items: values
    };
    var store = new dojo.data.ItemFileReadStore({
        data: dataItems
    });
    ...

That populated the dropdown with the field names.

Here is the docs on Combox with samples using the dojo/store to populate the dropdown.

0 Kudos
KeithAnderson
New Contributor III

Thank you again Rene.

It worked.

I will work to change the store.

Keith

0 Kudos