ExtJS4 store proxy url override

2020-07-24 13:31发布

I am trying to reuse a store by altering proxy url (actual endpoint rather than params). Is it possible to override proxy URL for a store instance wih the following syntax:

{
...some view config ...
store: Ext.create('MyApp.store.MyTasks',{proxy:{url:'task/my.json'}}),
}

if proxy is already well defined on the Store definition?

EDIT: AbstractStore source code sets proxy the following way

    if (Ext.isString(proxy)) {
        proxy = {
            type: proxy    
        };
    }

SOLUTION : store.getProxy().url = 'task/myMethod.json';

标签: Extjs extjs4
4条回答
迷人小祖宗
2楼-- · 2020-07-24 14:11

You cannot override the url of a proxy alone when creating a store. You will have to pass a complete proxy. This is because, the library replaces the proxy as a whole! So, what you can do is:

{
...some view config ...
store: Ext.create('MyApp.store.MyTasks',{
            proxy: {
                type: 'ajax',
                url : 'task/my.json',
                reader: {
                    type: 'json',
                    root: 'rows'
                }
            }
        }),
}

Now another possibility is, changing the end point after you have the instance of store. If you need to load the store from a different endpoint, you can make use of the load method.

store.load({url:'task/others.json'});

Since, in your case you are trying to re-use a store, you can pass the whole proxy. Your store's (MyApp.store.MyTasks) constructor should be capable of handling the new config and applying it to the store... Here is an example:

constructor: function(config) {

    this.initConfig(config);
    this.callParent();
} 
查看更多
爷、活的狠高调
3楼-- · 2020-07-24 14:15

Use the store.setProxy() method. Link here:

查看更多
做自己的国王
4楼-- · 2020-07-24 14:18
{
    ... some tab config ...
    store: Ext.create('MyApp.store.MyTasks'),
    listeners: {
        afterrender: function(tab) {
            tab.store.getProxy().url = 'task/myMethod.json'; //<--Saki magic :)
            tab.store.load();
        }
    }
}

http://www.sencha.com/forum/showthread.php?149809-Reusing-Store-by-changing-Proxy-URL

查看更多
Luminary・发光体
5楼-- · 2020-07-24 14:22

I have a BaseStore which I use to store default settings.

Ext.define('ATCOM.store.Shifts', {
    extend : 'ATCOM.store.BaseStore',
    model : 'ATCOM.model.Shift',
    constructor : function(config) {
        this.callParent([config]);
        this.proxy.api = {
            create : 'shifts/create.json',
            read : 'shifts/read.json',
            update : 'shifts/update.json',
            destroy : 'shifts/delete.json',
        };
    }
});
查看更多
登录 后发表回答