How to set url and root dynamically in extjs

mohan picture mohan · May 20, 2013 · Viewed 8.6k times · Source

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

Answer

smhg picture smhg · May 20, 2013

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');