PDA

View Full Version : Using loadData to Polpulate a second Combox after selecting one item on the first one



VisualOffice
4 Apr 2012, 9:08 PM
Hi Guys,
I'm a new EXTJS user.

I want to use one ComboBox for the Zipcode and a second for the town

After the user has selected an item in my first ComboBox, I use an AJAX request to my Oracle Database to populate a second ComboBox

but it don not work
My second ComboBox is populated with black lines (the number of blanck line is equal to the number of caracter returned by my AJAX request.!

I think the loadData function do not read correctly my data.

My code is there
Some one can help me please?


var ComboStore = new Ext.data.SimpleStore({
fields: [{ name: 'idville', type: 'int' }, { name: 'ville', type: 'string'}]
});

var panelDroiteO = new Ext.Panel({
id: 'panelDroiteO',
layout: 'form',
border: false,
frame: false,
items: [
new Ext.form.TextField({
fieldLabel: 'Sigle',
id: 'SigleO',
width: 200
}),
new Ext.form.ComboBox({
fieldLabel: 'CP',
id: 'CPO',
editable: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
displayField: 'cp',
hiddenField: 'hiddencp',
valueField: 'idCP',
store: storeCodePostalC,
listeners: {
select: function (a) {
var idD = Ext.getCmp('CPO').getValue();
Ext.Ajax.request({
method: 'GET',
url: "cs/Data.ashx?p=CodePostalCommune",
params: { "Methode": "LectureCommuneEnFonctionDuCP", "id": idD },
success: function (data, status) {
Ext.MessageBox.alert('Résultat', data.responseText);
Ext.getCmp('VilleO').getStore().loadData(data.responseText);
}
});
}
},
width: 200
}),
new Ext.form.ComboBox({
fieldLabel: 'Ville',
id: 'VilleO',
editable: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
displayField: 'ville',
hiddenField: 'hiddenville',
valueField: 'idville',
store: ComboStore,
width: 200
}),

my AJAX request is OK and returns this kind of Object

[[167,'PONTIS'],[212,'GUILLESTRE'],[213,'CEILLAC'],[214,'MONT DAUPHIN'],[215,'RISOUL']]

mitchellsimoens
5 Apr 2012, 8:33 AM
Why not use ajax proxy and array reader?