Ext.define('MyApp.data.proxy.CustomRestProxy', { override: 'Ext.data.proxy.Rest', buildUrl: function(request) { //here I simply add an url prefix to all rest calls var me = this, _serviceUrl = globalConf.serviceUrl, url = me.getUrl(request); request.setUrl(_serviceUrl + url); return me.callParent([request]); } });Put this class in a folder according to the name.
Mine is located in app/data/proxy/CustomRestProxy.js
In your app.js make sure to set this class as required.
requires: ['MyApp.data.proxy.CustomRestProxy']
When you start your App and Sencha complains it can't find your new class you have to tell Sencha where to look.
Put
Ext.Loader.setPath('MyApp', 'app');
Before you call
Ext.application ...
Thanks, so far, so good.
AntwortenLöschenBut I'm getting problems using this proxy in a store config:
Ext.define('JMA.store.MainStore', {
extend: 'Ext.data.Store',
config: {
...
proxy: {
type: 'JMA.data.proxy.WebApiRest',
}
}
}
yields
"Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: proxy.JMA.data.proxy.WebApiRest"
and
Ext.define('JMA.store.MainStore', {
extend: 'Ext.data.Store',
config: {
...
proxy: {
type: 'WebApiRest',
}
}
}
yields
"Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: proxy.WebApiRest"
Hi there,
AntwortenLöschenin my example I'm using an override so it is used automatically.
--> override: 'Ext.data.proxy.Rest',
Instead of an override you can use an extend.
In this case something like this should work:
proxy: new JMA.data.proxy.WebApiRest({
type: 'rest',
//rest of the config for this proxy ...
})