Davor Zubak
Davor Zubak

Reputation: 4746

Loading two different json with same store

Is there a way to load different json files on demand(click), somehow changing the URL. Same store, same model, just changing the url and load().

Ext.define('app.gridStore', {
    extend: 'Ext.data.Model',
    fields: [
        'name', 'email', 'phone'
    ]
});

var myStore =Ext.create('Ext.data.Store', {
    model: 'app.gridStore',
    proxy: {
        type: 'ajax',
        url : 'app/kontaktGrid.json',
        reader:{ 
            type:'json',
            root: 'items'
        }
    }


});

buttons: [{
   text: 'Load1',
   handler:function(){

   myStore.load().url('app/kontaktGrid1.json');

   }
   },{
   text: 'Load2',
   handler:function(){

   myStore.load('app/kontaktGrid2.json');--

returning POST 405 Method not allowed

   }
}]

Upvotes: 1

Views: 464

Answers (1)

Abdel Raoof Olakara
Abdel Raoof Olakara

Reputation: 19353

both myStore.load().url('app/kontaktGrid1.json'); or myStore.load('app/kontaktGrid2.json'); do not update the store URL for retriving data.

In order update the url, you need to do the following:

myStore.getProxy().url = "/new-url";
myStore.load();

The first statement modifies the store's proxy url. The load() which is then called, loads the new data to the store.

Upvotes: 1

Related Questions