gpt4 book ai didi

javascript - Extjs多重继承?

转载 作者:搜寻专家 更新时间:2023-11-01 04:11:29 25 4
gpt4 key购买 nike

我有一个关于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com