Javascript 需要具有相对名称的Ext JS类
在ExtJS中是否可能需要使用相对路径的类?假设我有这样一个目录结构:Javascript 需要具有相对名称的Ext JS类,javascript,extjs,Javascript,Extjs,在ExtJS中是否可能需要使用相对路径的类?假设我有这样一个目录结构: Ext.define('RootName.some.really.long.path.MyClass', { requires: ['RootName.some.really.long.path.MyClassDependency'], // Snipped. }); Ext.define('RootName.some.really.long.path.MyClassDependency', { /
Ext.define('RootName.some.really.long.path.MyClass', {
requires: ['RootName.some.really.long.path.MyClassDependency'],
// Snipped.
});
Ext.define('RootName.some.really.long.path.MyClassDependency', {
// Snipped.
});
批准
`-一些
`-真的吗
`-长的
`-路径
|-MyClass.js
`-MyClassDependency.js
而MyClass.js
看起来是这样的:
Ext.define('RootName.some.really.long.path.MyClass', {
requires: ['RootName.some.really.long.path.MyClassDependency'],
// Snipped.
});
Ext.define('RootName.some.really.long.path.MyClassDependency', {
// Snipped.
});
而MyClassDependency.js
是这样的:
Ext.define('RootName.some.really.long.path.MyClass', {
requires: ['RootName.some.really.long.path.MyClassDependency'],
// Snipped.
});
Ext.define('RootName.some.really.long.path.MyClassDependency', {
// Snipped.
});
有没有一种方法可以在不引用整个类名的情况下表达这种依赖关系?例如,我想移动
MyClass.js
和MyClassDependency.js
所在的文件夹,而不必更新MyClass.js
所拥有的每个依赖项。到目前为止,还没有标准的方法可以这样做。理论上,可以覆盖方法
Ext.ClassManager.define
,将当前“名称空间”前置到requires
数组中的类
Ext.override(Ext.ClassManager, {
define : function(className, data) {
//prepend data.requires with className
this.callSuper(arguments);
}
});
这样做,Sencha Cmd将无法再构建应用程序的缩小版本,因为它无法再解决需求,只要您不在构建中包含所有文件。我不会这样做,因为使用ExtJs更新破坏某些东西的风险是巨大的
另一种方法是使用通配符
Ext.define('TestApp.view.Main', {
requires: [
'TestApp.view.*'
]
});
我最后想到的是使用别名
Ext.define('TestApp.view.MainDep', {
alias: ['module1.mainDep']
});
Ext.define('TestApp.view.Main', {
requires: [
'module1.mainDep',
'module2.*',
]
});
到目前为止,还没有标准的方法来做到这一点。
理论上,可以覆盖方法
Ext.ClassManager.define
,将当前“名称空间”前置到requires
数组中的类
Ext.override(Ext.ClassManager, {
define : function(className, data) {
//prepend data.requires with className
this.callSuper(arguments);
}
});
这样做,Sencha Cmd将无法再构建应用程序的缩小版本,因为它无法再解决需求,只要您不在构建中包含所有文件。我不会这样做,因为使用ExtJs更新破坏某些东西的风险是巨大的
另一种方法是使用通配符
Ext.define('TestApp.view.Main', {
requires: [
'TestApp.view.*'
]
});
我最后想到的是使用别名
Ext.define('TestApp.view.MainDep', {
alias: ['module1.mainDep']
});
Ext.define('TestApp.view.Main', {
requires: [
'module1.mainDep',
'module2.*',
]
});