PDA

View Full Version : How do I apply a store to a combobox?



darkhorni
19 Feb 2013, 5:03 AM
{
fieldLabel: 'Tip',
name: 'SubjectType',
allowBlank: false,
xtype: 'combo',
displayField: 'name',
valueField: 'type',
typeAhead: true,
forceSelection: true,
queryMode: 'local',
store: subjectTypeStore,
listeners: {
select: function(a,selected,c){
//console.log(a);
var tets = selected[0].data.type;
console.log(tets);
//console.log(c);
}
}
},
{
name: 'SubjectID',
allowblank: false,
xtype: 'combo',
displayField: 'name',
valuefield: 'name',
typeAhead: true,
forceSelection: true,
queryMode: 'local'
}What I want to do is to apply a combobox store to the second combobox according to the selected item in the first combobox. For example if you select Pokemons then the second combobox should load pokemonStore. You change your mind and you select Smurfs, then the second combobox loads the smurfsStore.

What I want to learn is how to apply the store to an existent combobox.

scottmartin
19 Feb 2013, 11:59 AM
See if this will work for you:



var statesA = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});

var statesZ = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"ZL", "name":"ZAlabama"},
{"abbr":"ZK", "name":"ZAlaska"},
{"abbr":"ZZ", "name":"ZArizona"}
]
});

var comboA = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: statesA,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners: {
select: function(combo) {
comboZ.bindStore(statesZ);
}
}
});

var comboZ = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: null,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});


Scott.