J'ai un petit problème. A mon application Im toujours construire deux combobox liés - pays et villes (alors le pays est sélectionné - les villes ont commencé à charger). Alors j'ai pensé - mbe écrire un constructeur et minimisé mon code? Ok je l'ai fait. Mais j'ai un problème: j'ai 2-3 paires de comboboxes liées sur la page et quand j'ai sélectionné au deuxième pays combo, les données (villes) se chargent au premier combo, parce qu'il a le même id. Ok - maintenant j'essaye de prendre un identifiant de param au constructeur et cela n'a pas fonctionné. Comment définir id de combobox alors je crée un objet?ExtJS: Comment définir l'identifiant combobox?
combo Pays
comboCountryClass = Ext.extend(Ext.form.ComboBox, {
fieldLabel: 'country',
anchor: '95%',
lazyRender:true,
store:new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
{url: '../lib/getRFB.php?rfb_type=countrys',
method: 'GET'}
),
reader: countryReader,
autoLoad: true
}),
displayField:'country_name',
valueField:'country_id',
triggerAction:'all',
mode:'local',
listeners:{
select:{
fn:function(combo, value) {
var modelCmp = Ext.getCmp(this.town_name_id);
alert(this.town_name_id);
modelCmp.setValue('');
modelCmp.getStore().proxy.setUrl('../lib/getRFB.php');
modelCmp.store.reload({
params: { 'country_id': this.getValue(),rfb_type: 'towns' }
});
}
}
},
hiddenName:'country_id',
initComponent: function() {comboCountryClass.superclass.initComponent.call(this);}})
Et combo ville
comboTownClass = Ext.extend(Ext.form.ComboBox, {
fieldLabel:'town',
displayField:'town_name',
valueField:'town_id',
hiddenName:'town_id',
anchor: '95%',
id:this.town_name_id || 'youuuu',
store: new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
{url: 'lib/handlers/orgHandler.php?action=read&towns=true',
method: 'GET'}
),
reader: townReader
}),
triggerAction:'all',
mode:'local',
initComponent: function() {comboTownClass.superclass.initComponent.call(this);}})
nouvelle comboTownClass ({town_name_id: 'townFormSearch'})
nouvelle comboCountryClass ({town_name_id: 'townFormSearch'})
Voir ce screencast: http://tdg-i.com/392/ext-js-screencast-the-dangers-of-ext-getcmp pour quelques conseils sur (ne pas) utiliser les identifiants de composants. – Mchl