PDA

View Full Version : populate combobox from database



paulvonline
8 Jun 2010, 3:50 AM
Hi

I want to populate the ExtJs combo box from database. For that I declared an array and was able to fill that array from database. But when I used that array as the store, I was not able to populate my combo box


code for combo box

{
xtype:'combo',
fieldLabel: 'Country',
store:country,
name: 'subcountry',
anchor:'95%'
}




code for populating the array


var country=new Array();
PatientAjaxDwr.fetchCountries(callback=function(list){
for(var i=0;i<list.length;i++){
country[i]=list[i];
}
alert(country);
});


but if i hard code that array I can populate the combobox

like

country=['UK', 'US','NETHERLANDS'];


please help



Thanks and Regards
Paul

CrazyEnigma
8 Jun 2010, 12:39 PM
There are so many things wrong with your post. Duplicate post. CODE Tags.

Did you check the Tutorials? Are you using EXT JS's ArrayStore (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.ArrayStore) or Store to obtain the information? Did you specify the valueField and displayField? Did you read the API (http://www.extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox)? How does your fetchCountries return your data?

Too many questions that need to be answered.

paulvonline
9 Jun 2010, 12:26 AM
thanks crazy for ur reply

I am using the store to obtain data. fetchcountries is a dwr function which returns a javascript array, I am not using valuefield and displayField. If I hardcode the arrayvalues I am getting but if I retrieved it from database the combobox is not populating. I think the particular portion of the code(store:country) is executed before the array returns from db, how can I prevent this? ie if I give an alertbox before the portion(store:country) the combo box is populating, that by then the js array is returned.

the array values are returned correctly, how can I use that returned array to populate the combobox could anybody give me the code snippet for that

Regards
Paul



Regards
Paul

CrazyEnigma
9 Jun 2010, 10:50 PM
In the example above you are not using an ArrayStore, just a simple javascript array.