Extjs多重继承?
我有一个关于 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);
如果您认为您有更好的解决方案,请再次提供有用的建议:) 谢谢!
I have a question regarding multiple inheritance in ExtJS. While I know I can simply duplicate the code to make it happens, but I want to know if there is any way to code it more efficiently.
I have a customized GridPanel
component in my framework, called Kore.ux.grid.GridPanel
. It extends Ext.GridPanel
with extra common functionalities and provides interface for REST actions.
Soon later, my colleague wanted to have EditorGridPanel
to be also implemented in the same manner, ie, she wants it to be editable, and at the same time, have the ability to do REST actions easily.
My question is, is there any way I can extend Ext.EditorGridPanel
to take up the customized Kore.ux.grid.GridPanel
functionalities?
Sorry for any grammar errors and I can rephrase it if it's confusing. Thanks!!
EDIT
I googled again, and I found threads saying it's impossible. Is there any better coding pattern I should follow if I have this problem?
Thanks!
EDIT AGAIN
So sorry I found the structure that suits me.. Here is the method I found useful to me:
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);
Code Source: http://www.sencha.com/forum/showthread.php?48000-multiple-inheritance&p=228271&viewfull=1#post228271
Please again provide useful suggestions if you think you have a better solution :) Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你真正需要研究的是 ExtJS 插件。
用法
What you really need to look into, are ExtJS plugins.
Usage
创建
Kore.ux.grid.AbstractGridPanel
作为具有通用功能的基类。并创建两个子类:Kore.ux.grid.GridPanel
和Kore.ux.grid.EditorGridPanel
(具有特定功能)。Create
Kore.ux.grid.AbstractGridPanel
as base class with general functionality. And create two child classes:Kore.ux.grid.GridPanel
andKore.ux.grid.EditorGridPanel
(with specific functionality).我不同意在Ext中使用Plugins来完成多重继承。插件旨在改变行为或添加新功能。
实现多重继承的正确方法是使用 Mixins,请观看这个精彩的解释SenchaCon 2011:Sencha 类系统
I don't agree with using Plugins to accomplish multiple inheritance in Ext. Plugins are intended to changed behaviour or add new functionality.
The right way to achieve multiple inheritance is by using Mixins, please watch this amazing explanation SenchaCon 2011: The Sencha Class System