How to populdate the dijit.form.ComboBox by calling the URL which will returns JSON data?

146 views Asked by At

I have a combox box component in the dojo datagrid like

var tacStore = {items:[]}; Tac

And i have button when i clicked the button am trying to populate the Combo box using below code.

        function loadTimeZones() {

        dojo.xhrGet({
                //url: "/AAORPCAdapterServicesWeb/RPCAdapter/httprpc/TimeZoneService/getTimeZones",
                url: "/AAORPCAdapterServicesWeb/RPCAdapter/httprpc/DeliverableService/getAllTacs",
                handleAs:"json",
                load: createTimeZoneStore,
                error: function(error,ioargs){
                  console.log(error);
                }
            });
        return false;
    }

         function  createTimeZoneStore(response) {
        console.log("createTimeZoneStore::response:: "+response);
        if ( response.result != null) {
            var timezone = [];
            for(var resultCounter=0; resultCounter<response.result.length;resultCounter++)
            {
                timezone[resultCounter] = {};
                timezone[resultCounter]['name']=response.result[resultCounter];
                console.log("createTimeZoneStore::response.result[resultCounter]:: "+response.result[resultCounter]);
            }
            console.log("createTimeZoneStore::tacStore::tacs: "+tacStore);
            tacstore= new dojo.data.ItemFileWriteStore({data:{items:timezone}});
        }
        return false;
    }

Am getting response. But the values are not showing in the combobox. And when i click on combo box am getting error like this.fetch is not a function

1

There are 1 answers

2
Elad On

First, you are using ItemFileWriteStore, which is the old dojo/data/api API. Combo box uses the newer dojo/store/api API (specifically, you can use the dojo/store/Memory implementation).

var myStore = new Memory({data: timezone});

Also, you are creating the store, but not connecting it to the ComboBox. If you are programatically creating the ComboBox, use

var myComboBox = new ComboBox({store: myStore});
myComboBox.placeAt(/* wherever you like */);
myComboBox.startup();

If the ComboBox is already created (either programatically, or using markup with data-dojo-id), use

myComboBox.set('store', myStore);
/* you may need to startup the ComboBox after this - but I am not sure */
myComboBox.startup();