简体   繁体   English

ExtJS4-从单个基类扩展不同的组件

[英]ExtJS4 - Extending different components from a single base class

I have a web app for which I am using ExtJS 4.2. 我有一个Web应用程序,正在使用ExtJS 4.2。 This application has a bunch of different components - a panel that displays some data, another panel that displays some other data, a grid, a chart, etc, etc. 该应用程序具有许多不同的组件-一个显示一些数据的面板,另一个显示一些其他数据的面板,一个网格,一个图表等。

It's required that each component has at minimum a specific set of functions and properties. 要求每个组件至少具有一组特定的功能和属性。 So I'd like to define a 'component' class that I can extend everything else from. 因此,我想定义一个“组件”类,我可以从中扩展其他所有内容。 For example: 例如:

Ext.define('MyApp.BaseComponent', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.myapp-basecomponent',

    prop1: true,
    prop2: 17,

    func1: function (a, b) {
        return a + b;
    }
});

Then I would extend every individual component in my app from that base component class. 然后,我将从该基本组件类扩展应用程序中的每个单独组件。 The problem is that if I define the base component as extending 'Ext.panel.Panel', I can only extend other panels from it. 问题是,如果我将基本组件定义为扩展“ Ext.panel.Panel”,则只能从中扩展其他面板。 I can't extend a grid, tree, etc, etc from it. 我无法从中扩展网格,树等。

Is there a way I can accomplish this? 有没有办法可以做到这一点? Or am I approaching this the wrong way? 还是我走错路了? Maybe I should just nest everything that's not a panel (grid, chart, etc) in a panel so they can all extend from BaseComponent? 也许我应该将不是面板的所有内容(网格,图表等)嵌套在面板中,以便它们都可以从BaseComponent扩展出来? Advice greatly appreciated. 忠告不胜感激。

If you just want to augment the base component class, you could always just provide an override that adds them: 如果只想增加基本组件类,则总是可以提供一个添加它们的覆盖:

Ext.define('MyApp.AugmentComponent', {
    override: 'Ext.Component',

    a: 1,
    b: 2,

    fn1: function() {
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM