PDA

View Full Version : How to change a single combobox option?



mice-pace
3 Mar 2013, 10:00 PM
I'm using a seleected value from a combobox to return the Model from it's store, but i'm not sure how to have changes reflected back to the store and then back on again to the combobox. Has anyone tried this before?

mitchellsimoens
5 Mar 2013, 11:35 AM
I'm not sure I know what you mean. If you set a value to a field on a model and it's within a store the store will fire the datachanged event and the combobox will automatically reflect that change.

mice-pace
5 Mar 2013, 3:01 PM
Thanks mitchellsimoens... That's solved part of the problem.

You got me thinking 'maybe i've just been overcomplicating this'... So i mocked up a little test case, and your advice was pretty good, it's solved Half of my problem... When i click a button the code below runs, and that successfully changes the list of options on the combobox... But it doesn't change the 'Value' of the combobox (the text), which stays showing the old value

var combo = Ext.getCmp('combo');
var oldData = combo.getValue();
var newValue = '1st Scope';
var store = combo.getStore();
var first = store.first();
//alert(Object.keys(first.data));
first.set('name', newValue);
combo.select(first);
combo.setValue(newValue);
alert("click");

Since then i'd tried making the store load() (which causes errors since it is queryMode local), made the Store autoload and tried both setValue() and select() on the combobox, none of which caused the displayed value to change after changing the model.

In case it helps, here's the code for my Store, below

Ext.define('MyApp.store.Scopes', {
extend: 'Ext.data.Store',

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'MyJsonStore1',
data: [
{
name: 'First Scope',
report: 'This scope report finds damage to 4 Rooms, 2 Bathrooms, 2 Bedrooms:',
Id: 0
}
],
proxy: {
type: 'ajax',
reader: {
type: 'json'
}
},
fields: [
{
name: 'name'
}
]
}, cfg)]);
}
});