javascript - Extjs多重继承?

标签 javascript inheritance extjs gridpanel

我有一个关于 ExtJS 多重继承的问题。虽然我知道我可以简单地复制代码来实现它,但我想知道是否有任何方法可以更有效地对其进行编码。

我的框架中有一个自定义的 GridPanel 组件,名为 Kore.ux.grid.GridPanel。它使用额外的通用功能扩展了 Ext.GridPanel,并为 REST 操作提供了接口(interface)。

不久之后,我的同事想让 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

如果您认为您有更好的解决方案,请再次提供有用的建议:)谢谢!

最佳答案

您真正需要研究的是 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'
  ]
}

关于javascript - Extjs多重继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4930723/

相关文章:

javascript - 如何在 Ext js 6 中全局覆盖 startParam 和 limitParam 名称

javascript - ES6中的静态导入是什么意思?

python - 在子类python中调用基类方法

c++ - 静态字段是否继承?

c# - MSTest,当具有测试类继承时,[ClassCleanup] 调用何时发生

html - 固定表格td的宽高

extjs - 如何在extjs中隐藏水平线

javascript - 如何使用 javascript 将样式附加到 html 中的现有内联样式?

javascript - 是否可以使用 NodeMailer 将回复字段设置为抄送?

javascript - 我想在 JavaScript 中验证我的必填字段不为空