ExtJS: Combobox does not set value after reboot

I think I have a very popular problem, but now I have not found the answer. :) I have 2 similar comboboxes - first I set my value to id - comboT.setValue("22763");and correctly sets the text value associated with this id. In the second combobox, I first reboot the repository (jsonstore), and then set the value - comboC.setValue("3");But this combo sets only the ID not the text value (if I open the list, I can see which combo the text value is correctly marked. And after (if the list just closes without of choice) text value displayed correctly in combo. How to solve this problem? Thanks.

+3
source share
4 answers

Something like this, the syntax may be slightly disabled, as I am doing this from memory:

var val = 3;
var store = comboC.getStore();
store.on("load", function() {
   comboC.setValue(val);
}):
store.load();
+11
source

Loading asynchronous storage, you may need to move the value of the new value to the event handler callback: store.load({...}), because otherwise you set the value before loading the store.

EDIT: for completeness, an example, so you have an alternative version (in some cases it would be inappropriate to associate a callback with the store itself, for example, ormuriauga):

var val = 3;
var store = comboC.getStore();
store.load({
   callback: function() {
      comboC.setValue(val);
   }
});
+6
source

, combobox . , :

//The store data definition must have at least a data.id field defined    
set_combobox_value_from_store = function (combobox, valueField, value) {
//Get a reference to the combobox underlying store
var store = combobox.getStore();
store.load({
    callback: function () {
        //Find item index in store
        var index = store.find(valueField, value, false);
        if (index < 0) return;
        //Get model data id
        var dataId = store.getAt(index).data.Id;
        //Set combobox value and fire OnSelect event
        combobox.setValueAndFireSelect(dataId);
    }
});
+2

extjs 4.1 combo.setValue(), Field "".

Ext.define('Model.CboObras', {
               extend: 'Ext.data.Model',
                idProperty: 'co_obra',
                fields: [{
                    name: 'co_obra',
                    type: 'int'
                }, {
                    name: 'nb_obra',
                    type: 'string'
                }]
            });

this does not work.

When I changed my code to this:

   Ext.define('Model.CboObras', {
      extend: 'Ext.data.Model',
      idProperty: 'co_obra',
      fields: [{
         name: 'co_obra',
             type: 'string'
          }, {
             name: 'nb_obra',
            type: 'string'
         }]
   });

After that, I use this:

    var store = comboC.getStore();
    store.load({
   callback: function() {
      comboC.setValue(val);
   }
});

Now it works like a charm!

+1
source

Source: https://habr.com/ru/post/1766277/


All Articles