扩展Ext.data.Store

Jim*_*els 6 extjs extending extending-classes

我试图在我的应用程序中集中我的EXTJS存储配置,但是,我似乎无法弄清楚如何实现这一点.我正在使用ExtJS 4.1.

我有一个基础商店,我希望保留所有重复配置的东西,然后我更具体的商店来保存实际上不同的东西.

Ext.define('My.store.Abstract', {
    extend: 'Ext.data.Store',
    autoload:false,
    proxy: {
        type: 'ajax', 
        reader: {  
            type: 'json',
            root: 'data',
            totalProperty: 'total',  
            successProperty: 'success', 
            messageProperty: 'message'  
        },
        writer: {  
            type: 'json',
            encode: true, 
            writeAllFields: true, 
            root: 'data',
            allowSingle: false 
        },
        simpleSortMode: true
    }
});
Run Code Online (Sandbox Code Playgroud)

然后我想在商店的基础上提供商店特定的东西 -

Ext.define('My.store.Products', {
    extend: 'My.store.Abstract',
    storeId: 'Products',
    model: 'My.model.Product',
    proxy: {
        api: {
            create: '/myurl/create',  
            read: '/myurl/index',
            update: '/myurl/update',  
            destroy: '/myurl/delete' 
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

我发现的是它根本就没有表现.我相信它与代理有关,但我无法追踪它.

这样做的正确方法是什么?我宁愿不在我的应用程序中的350多个商店中复制相同的配置内容(来自我的抽象商店).截至目前,它就是我所拥有的,而且我认为我试图实现一个非常基本的概念......无济于事.

我知道事情不起作用,像pageSize一样基本,甚至是autoLoad ..因为它们根本没有受到尊重.

我玩过构造函数,并调用父代.

任何帮助将不胜感激.

Eva*_*oli 10

你不能这样做,因为你期望合并它不会做的对象.

相反,你会想看看这样的事情(未经测试):

Ext.define('Base', {
    extend: 'Ext.data.Store',

    autoLoad: false,

    constructor: function(config) {
        // applyIf means only copy if it doesn't exist
        Ext.applyIf(config, {
            proxy: this.createProxy()
        });
        this.callParent([config]);
    },

    createProxy: function() {
        return {
            reader: {
                type: 'json',
                root: 'data',
                totalProperty: 'total',
                successProperty: 'success',
                messageProperty: 'message'
            },
            writer: {
                type: 'json',
                encode: true,
                writeAllFields: true,
                root: 'data',
                allowSingle: false
            },
            simpleSortMode: true
        }
    }
});

Ext.define('Sub', {
    extend: 'Base',

    createProxy: function(){
        var proxy = this.callParent();
        proxy.api = {
            create: 'create',
            update: 'update'
        };

        return proxy;
    }
});
Run Code Online (Sandbox Code Playgroud)