Search code examples
extjsextjs4.1sencha-architectextjs4.2

How to set url and root dynamically in extjs


Can anybody tell how to set the url and root of a store dynamically in Ext JS?

I have created a store like the one below. I need to update the root and dynamically set the url inside a controller.

Ext.define('Test.store.TestStore', {
  extend: 'Ext.data.Store',
  model: 'Test.model.TestModel',
  storeId: 'testStore',
  proxy: {
    type: 'jsonp',
    reader: {
      type: 'json',
      root: 'responseXML'
    }
  }
});

Thanks


Solution

  • You can set the proxy's url later in your code this way:

    store.getProxy().url = '/your/url';
    

    After that you can just do the regular:

    store.load();
    

    or let it be triggered automatically by any binding.

    Anywhere in your code you can retrieve the store through the StoreManager:

    var store = Ext.data.StoreManager.lookup('myStore');