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

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?

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.

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();
first.set('name', newValue);

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 || {};
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)]);