3

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

smhg
  • 2,159
  • 19
  • 26
mohan
  • 13,035
  • 29
  • 108
  • 178

1 Answers1

7

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');
smhg
  • 2,159
  • 19
  • 26
  • I did not test this, but in that case you can probably do `store.getProxy().getReader().root = '/your/root';`. – smhg May 20 '13 at 10:26
  • I don't really know if Sencha restructured their own components' properties to use the magic getters and setters, but if so, it is even cleaner to do: `store.getProxy().setUrl('/your/url');` The same of course applies for the root property of the reader. – smhg May 20 '13 at 10:36