Question

I have a Problem. I am writing a ComboBox on dojo and if the user is writing an option which is not yet in the store it will be added.

I have wrote a keyup Event and it will be triggered if the user hits RETURN or ENTER

if(pressed.keyCode == keys.ENTER){
                //var dtemp = dijit.byId("stateSelect").get("store");
                var MyMemory = new myownclass();
                var value = dijit.byId('stateSelect').get('value');
                var isNew = true;
                var d = new Memory({data : []});
                for(var vi = 0; MyMemory.data[vi].name != "";vi++)
                {
                    d.put({name : MyMemory.data[vi].name, id : MyMemory.data[vi].id});
                }
                for(var index = 0; index < d.length ; index++)
                {
                    if(value == d[index].name)
                    {
                        //alert(value);
                        isNew = false;
                    }
                    //isNew = true;
                }
                if(isNew == true){
                    MyMemory.setdata(value);
                    //var newData = new myownclass();
                    d.put({name : value, id : vi});
                    //dijit.byId('stateSelect').get('store').reset();
                    dijit.byId('stateSelect').get('store').setData(d);

                }
            }
            if(pressed.keyCode == keys.F2){
                var MyMemory = new myownclass();
                var value = dijit.byId('stateSelect').get('value');
                    MyMemory.deletedata(value);
                    //var temp = new myownclass();
                    //dijit.byId('stateSelect').get('store').remove(dijit.byId('stateSelect').get('store').get('id'));

            }

The Problem is that it does not want to replace the old store with the new store d! Instead the ComboBox is completely empty :(

The var d has content inside Firebug Screen

anyone who knows why it won't display the Options?

Thanks for Help

Was it helpful?

Solution

Because you're using setData() incorrect. The setData() expects an array of objects to be inserted. However, you're using it to insert d, which is a store by itself. So, the correct way of setting the data would by by using:

dijit.byId('stateSelect').get('store').setData(d.query());

Because if you use the query() function without parameters, it will return all objects inside the store (as an array).

However, you could also directly change the store of the combobox by using:

dijit.byId('stateSelect').set('store', d);

Here's a simple example using the store setter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top