Ext JS:覆盖initComponent中的Ext.Array.merge

时间:2018-04-07 09:50:54

标签: javascript function extjs override

如何更改/覆盖子类中Ext.Array.merge内的initComponent的顺序?

当我override子类中的顺序时,当我只是extend基本面板时,它仍会在基类中使用相同的merge顺序时出错。

一些片段:

Ext.define('MyApp.BasePanel', {
extend: 'Ext.panel.Panel',
    initComponent: function () {
        var me = this;

        me.items = Ext.Array.merge(me.firstFunc(), me.secondFunc(), me.thirdFunc());

        me.callParent(arguments)
    },

    firstFunc: function () {
        return [];
    },

    secondFunc: function () {
        return [];
    },

    thirdFunc: function () {
        return [];
    },

在这种情况下,我需要打电话给;

me.items = Ext.Array.merge(me.secondFunc(), me.firstFunc(), me.thirdFunc());

我试图覆盖基类,但它给了Synch。加载错误;

Ext.define('MyApp.SubPanel', {
    override: 'MyApp.BasePanel',
        initComponent: function () {
            var me = this;

            me.items = Ext.Array.merge(me.secondFunc(), me.firstFunc());

            me.callParent(arguments)
        },

        secondFunc: function () {
            return [];
        },

        firstFunc: function () {
            return [];
        },


// Error: [W] [Ext.Loader] Synchronously loading 'MyApp.SubPanel'; consider adding Ext.require('MyApp.SubPanel') above Ext.onReady

1 个答案:

答案 0 :(得分:2)

即使你按照你的描述覆盖它,callParent()也只会破坏你的子类所做的事情。提供模板方法作为钩子:

delete/re-add