PDA

View Full Version : dynamically load proxy url of Ext.data.Store



clabasky
7 Sep 2011, 2:44 PM
I'm trying to dynamically load the url proxy of an Ext.data.Store.

a user would enter a zipcode into a field, and the zipcode would be loaded into the url proxy, it would look something like this



ListStore = new Ext.data.Store({
model: 'currentpost',
proxy: {
type: 'ajax',
url: '(zipcode entered from field goes here).json',
reader: {
type: 'json'
}
}
});


there would be .json files saved that would correspond to the zipcode specified.

Any help on how I could make this work would be awesome!!!!:D

NickT
8 Sep 2011, 4:38 PM
You can call setProxy on your store to accomplish this. just add logic similar to this to your change event listener for your zip code field and drop in the proxy configuration you want.


vm.accounts.setProxy({ type: 'ajax',
url : vm.environ.server.routePrefix + '/readaccounts',
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalRecords'
}
});

mobileme
8 Sep 2011, 7:54 PM
ListStore.proxy.url = 'youZipCode.json';
ListStore.load();

B)

clabasky
9 Sep 2011, 6:57 AM
thanks! I'll try these solutions today. >:)

clabasky
9 Sep 2011, 1:11 PM
ListStore.proxy.url = 'youZipCode.json';
ListStore.load();

B)

This worked great!
this is what my final code looked like




Ext.regController('larry', {
refresh: function() {


var currentzip = zipcodefield.getValue()

ListStore.proxy.url = currentzip+'.json';

ListStore.load();

}
});



zipcodefield is the field where the user types in the zipcode, and a refresh button dispatches to larry, with the refresh action. boom and walla, the mystery is solved!!:))