5

ExtJS の多重継承について質問があります。コードを複製するだけで実現できることはわかっていますが、より効率的にコーディングする方法があるかどうかを知りたいです。

私のフレームワークには、 というカスタマイズされたGridPanelコンポーネントがありKore.ux.grid.GridPanelます。追加の一般的な機能で拡張Ext.GridPanelし、REST アクションのインターフェースを提供します。

すぐ後に、私の同僚EditorGridPanelも同じ方法で実装する必要があることを望んでいました。つまり、編集可能にすると同時に、REST アクションを簡単に実行できるようにしたいと考えていました。

私の質問は、Ext.EditorGridPanelカスタマイズされたKore.ux.grid.GridPanel機能を利用するために拡張できる方法はありますか?

文法上の誤りがありましたら申し訳ありません。混乱している場合は、言い換えることができます。ありがとう!!

編集

もう一度ググったところ、不可能だというスレッドが見つかりました。この問題が発生した場合に従うべきより良いコーディング パターンはありますか?

ありがとう!

もう一度編集

申し訳ありませんが、私に合った構造を見つけました..これが私にとって便利な方法です:

var Common = function(){}   //abstract class
Ext.apply(Common.prototype, {

    a : function(){},
    b: function(){}...

});

Ext.ux.SomePanelA = Ext.extend ( Ext.Panel, {

    stuff : ............

});

Ext.ux.SomePanelB = Ext.extend ( Ext.Panel, {

    diffStuff : ............

});

Ext.applyIf(Ext.ux.SomePanelA.prototype, Common.prototype);
Ext.apply(Ext.ux.SomePanelB.prototype, Common.prototype);

コードソース: http://www.sencha.com/forum/showthread.php?48000-multiple-inheritance&p=228271&viewfull=1#post228271

より良い解決策があると思われる場合は、再度有用な提案を提供してください:)ありがとう!

4

3 に答える 3

5

本当に調べる必要があるのは、ExtJS プラグインです。

/**
 * Boilerplate code taken from 'ExtJS in Action' by Jay Garcia
 */
YourNameSpace.RestGridPlugin = Ext.extend(Object, {
  constructor : function(config) {
    config = config || {};
    Ext.apply(this.config);
  },

  init : function(parent) { //parent argument here, is whatever you apply your plugin to
    parent.on('destroy', this.onDestroy, this);
    Ext.apply(parent, this.parentOverrides);
  },

  onDestroy : function() {
    //here you need to free any resources created by this plugin
  },

  parentOverrides : {
    //here you do your magic (add functionality to GridPanel)
  }

});

Ext.preg('restgridplugin',YourNameSpace.RestGridPlugin); //register your brand ne plugin

使用法

someGrid = {
  xtype: 'grid',
  columns: ...
  store: ...
  plugins: [
    'restgridplugin'
  ]
}

someEditorGrid = {
  xtype: 'editorgrid',
  columns: ...
  store: ...
  plugins: [
    'restgridplugin'
  ]
}
于 2011-02-08T08:43:34.280 に答える
0

プラグインを使用して Ext で多重継承を実現することに同意しません。プラグインは、動作の変更または新しい機能の追加を目的としています。

多重継承を実現する正しい方法は Mixins を使用することです。この素晴らしい説明をご覧くださいSenchaCon 2011: The Sencha Class System

 Ext.define('FunctionalityA', {
     methodA: function () {
         ...
     }
 });

 Ext.define('FunctionalityB', {
     methodB: function () {

     }
 });

 Ext.define('MultipleFunctionality', {
     mixins: [
         'FunctionalityA',
         'FunctionalityB'
     ],

     method: function () {
         methodA();
         methodB();
     }
 });
于 2015-07-05T02:17:23.223 に答える
0

Kore.ux.grid.AbstractGridPanel一般的な機能を持つ基本クラスとして作成します。そして、2 つの子クラスを作成します: Kore.ux.grid.GridPaneland Kore.ux.grid.EditorGridPanel(特定の機能を持つ)。

于 2011-02-08T08:18:57.030 に答える