ExtJS4 store proxy url override

烂漫一生 提交于 2019-12-21 21:43:00

问题


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';


回答1:


{
    ... 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




回答2:


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:


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




回答4:


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',
        };
    }
});


来源:https://stackoverflow.com/questions/7670001/extjs4-store-proxy-url-override

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!