如何解决我们如何覆盖Ext.Base?
我正在使用Ext JS v7.1,并且已经重写Ext.Base
来设置从Ext.Base继承的类的命名方案:这简化了调试。
Ext.define('App.class.Base',{
override: 'Ext.Base',constructor: function() {
var me = this
/**
* App.base.store.Base => store-base-
* App.store.Menu => store-menu-
*/
if (me.isIdentifiable) {
if (!me.self.prototype.hasOwnProperty('identifiablePrefix')) {
const classNameParts = me.$className.match(/([^\.]+)/g)
if (classNameParts && classNameParts[0] === 'App') {
classNameParts.splice(0,classNameParts.length - 2)
me.self.prototype.identifiablePrefix = classNameParts.reduce((i,j) => i + '-' + j).toLocaleLowerCase() + '-'
}
}
}
return me.callParent()
}
})
此代码在构建之前没有错误,但是在我将Sencha Cmd升级到v7.3.0.19之后,我开始出现以下错误:
[ERR] C2016: Override target not found -- /...../packages/local/module-core/overrides/class/Base.js:2:64
[WRN] Override App.class.Base in file /..../packages/local/module-core/overrides/class/Base.js had no target detected
我不知道这是否是进行此覆盖的正确方法,否则我可以更改实现。但是,如果没有其他方法,如何摆脱构建错误?
预先感谢
Ipek
解决方法
由于我不再使用sencha构建工具,因此我无法直接为您提供帮助,但我想分享另一种方法:
如果您首先加载了框架(ext-debug-all或ext-all等),并且已经定义了应该覆盖的类,则可以这样操作:
Ext.Component.override({
initComponent: function () {
Ext.log('bootstraping ' + this.self.getName());
var me = this,width = me.width,height = me.height;
// If plugins have been added by a subclass's initComponent before calling up to here (or any components
// that don't have a table view),the processed flag will not have been set,and we must process them again.
// We could just call getPlugins here however most components don't have them so prevent the extra function call.
if (me.plugins && !me.plugins.processed) {
me.plugins = me.constructPlugins();
}
me.pluginsInitialized = true;
// this will properly (ignore or) constrain the configured width/height to their
// min/max values for consistency.
if (width != null || height != null) {
me.setSize(width,height);
}
if (me.listeners) {
me.on(me.listeners);
me.listeners = null; //change the value to remove any on prototype
}
if (me.focusable) {
me.initFocusable();
}
}
});
根据进一步的内部处理,您可以调用callParent或callSuper。 这里有更多详细信息:
例如,在Ext.isReady时,您也许可以在函数中移动此较高代码,然后再调用它。我想这可以解决或解决您面临的一些开放工具问题。
更新:
回到您的问题,您可以执行以下操作并定义它:
Ext.Base.override({
constructor: function() {
var me = this
/**
* App.base.store.Base => store-base-
* App.store.Menu => store-menu-
*/
if (me.isIdentifiable) {
if (!me.self.prototype.hasOwnProperty('identifiablePrefix')) {
const classNameParts = me.$className.match(/([^\.]+)/g)
if (classNameParts && classNameParts[0] === 'App') {
classNameParts.splice(0,classNameParts.length - 2)
me.self.prototype.identifiablePrefix = classNameParts.reduce((i,j) => i + '-' + j).toLocaleLowerCase() + '-'
}
}else{
console.log('isIdentifiable');
console.log(me.identifiablePrefix);
}
}
return me.callParent(arguments)
}
});
我在这里加了一个小提琴小提琴。如果设置了identifiablePrefix,则应记录“ helloWorld”。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。