Search code examples
extjscomboboxstore

Extjs one store bind to more combobox


I have one problem about:one store bind to more comboboxes;

for example

combobox_1 bind to store_1, and the combobox_2 also bind to store_1 ,when expand the combobox_1, the store_1 is loaded. Then expand the combobox_2, the store_1 load again.

but I don't want to load the store_1 twice, because the store has been loaded already! How can I solve this problem?


Solution

  • For example, on Controller, we will use a function on load combo store event:

    init : function() {
    
       this.getNameComboStore().on('load', this.functionLoadStore, this); 
    
    },
    
    ...
    
    functionLoadStore : (store){
    
     if(store.count>0){
       store.suspendEvents(false); // break the load event (supends all events)
       store.resumeEvents(); // resume the event, it's IMPORTANT!
     }
    
    }
    

    In the function, we compare the number of elements charge, if count>0, supend the load event, and resume again.