ExtJS4存储代理URL覆盖

时间:2011-10-06 03:15:53

标签: extjs extjs4

我试图通过改变代理URL(实际端点而不是params)来重用商店。是否可以使用以下语法覆盖商店实例的代理URL:

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

如果已在商店定义中明确定义了代理?

编辑:AbstractStore源代码按以下方式设置代理

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

解决方案:store.getProxy()。url ='task / myMethod.json';

4 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

创建商店时,不能单独覆盖代理的URL。您必须通过完整的代理。这是因为,库替换了代理作为一个整体!所以,你能做的是:

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

现在另一种可能性是,在拥有商店实例后更改结束点。如果需要从其他端点加载存储,则可以使用加载方法。

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

因为在您尝试重新使用商店的情况下,您可以传递整个代理。您的商店(MyApp.store.MyTasks)构造函数应该能够处理新配置并将其应用到商店......以下是一个示例:

constructor: function(config) {

    this.initConfig(config);
    this.callParent();
} 

答案 2 :(得分:0)

使用store.setProxy()方法。 Link here:

答案 3 :(得分:0)

我有一个BaseStore用于存储默认设置。

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',
        };
    }
});
相关问题