views:

410

answers:

2

Hello guys.

I think I have a very popular problem, but not found answer for it now. :) I got 2 similar comboboxes - at first i set my value by id - comboT.setValue("22763"); and it properly set a text value linked with this id. At second combobox i at first reload store(jsonstore) and then set value - comboC.setValue("3"); But this combo set only ID not text value (if i open list i can see what combo properly marked text value. And after (if list simply close without select) text value properly displayed at combo. How to solve this problem? Thanks.

+2  A: 

Loading the store is asynchronous, you might want to move setting the new value into the callback: event handler of store.load({...}), because otherwise, you set the value before the store is actually loaded.

EDIT: for completeness, an example, so you have an alternative version (in some cases it might be undesireable to bind the callback to the store itself, like ormuriauga did):

var val = 3;
var store = comboC.getStore();
store.load({
   callback: function() {
      comboC.setValue(val);
   }
});
ammoQ
big thanks to you. Im understanding now :)
0dd_b1t
+2  A: 

Something like this, syntax may be slightly off since I am doing it from memory:

var val = 3;
var store = comboC.getStore();
store.on("load", function() {
   comboC.setValue(val);
}):
store.load();
ormuriauga
wow. it works! ammoQ tell me why. Thanks a lot guys!
0dd_b1t