ExtJs 6存储在Ext.app.Controller上的配置不起作用 [英] ExtJs 6 stores config on Ext.app.Controller not working
问题描述
我刚刚注意到,商店配置
以前没有关键的MyApp.controller(ZHT.controller)
Ext.getNameSpace做的是查找最深的前缀,你可以在这里看到 http://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Util.html#Ext-app-Util
[update]
所以可以做的一件事是重写静态方法resolveNamespace,如下所示:
静态:{
resolveNamespace:function(cls,data){
var Controller = Ext.app.Controller,
namespaceRe = cls.prototype.isProfile? Controller.profileRegex:Controller.controllerRegex,
className,namespace,match;
/ *
*命名空间解析是棘手的事情:我们应该知道这个Controller后代属于哪个命名空间
*,或者model / store / view依赖关系
*解析将是不明确的或显然不可能。为了避免
*猜测游戏,我们尝试寻找
*应用程序类在其onClassExtended处理时设置的向前提示($命名空间)如果
*失败,我们尝试从类名称推导出命名空间。
*
*请注意,对于Ext.app.Application,Controller.onClassExtended在* Application.onClassExtended之前执行
* *,所以我们必须延迟命名空间处理
*直到应用程序.onClassExtended踢,因此它在这个钩子中完成。
* /
className = Ext.getClassName(cls);
namespace = data。$ namespace || data.namespace ||
Ext.app.getNamespace(className)||
((match = namespaceRe.exec(className))&& match [1]);
//< debug>
if(!namespace){
Ext.log.warn(缺少+ className +的命名空间,请在应用程序类的namespaces属性中定义+
。) ;
}
//< / debug>
//这是覆盖上唯一的变化。
//http://stackoverflow.com/questions/37731213/extjs-6-stores-config-on-ext-app-controller-not-working/37733261#37733261
if(namespace& & namespace.indexOf(。controller)> -1){
namespace = namespace.slice(0,namespace.indexOf(。controller));
}
返回命名空间;
}
}
如果你知道更好的解决方案,请让我知道!
I just noticed that stores config http://docs.sencha.com/extjs/6.0/6.0.2-classic/#!/api/Ext.app.Controller-cfg-stores on Ext.app.Controller is not looking in the right path (happens the same with views config).
e.g
Ext.define('MyApp.controller.Menu', {
extend: 'Ext.app.Controller',
stores: ['Menu']
...
});
this will look for
http://localhost/myapp/app/controller/store/Menu.js?_dc=20160607211025
notice the controller folder
instead of
At the beginning I thought this was a configuration issue specific to one of my projects but then got the same thing on a different project.
I am using ExtJs 6.02
I know I can use the full class name like MyApp.store.Menu but then the getter would be very ugly. (This is happening on a huge code base that I just upgraded so using the full class name would be my last resource).
Has someone faced this issue ?
I've found the reason (bare with me):
https://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Controller2.html#Ext-app-Controller
look at:
onClassExtended -> Controller.resolveNamespace -> Ext.app.getNamespace
Those are the important ones, once the namespace is resolved there is a call to process dependencies:
Controller.processDependencies(proto, requires, namespace, 'store', data.stores);
I researched this and Ext.app.getNamespace is identical in ext 5 and 6
so why is it in ExtJs 5
Ext.getNamespace("MyApp.controller.SomeController"); // returns MyApp
and on ExtJs 6
Ext.getNamespace("MyApp.controller.SomeController"); // returns MyApp.controller
The reason is found by console.log Ext.ClassManager.paths
there is now a new entry that corresponds to MyApp.controller
previously there was no key for MyApp.controller (ZHT.controller)
And what Ext.getNameSpace does is look for the 'deepest prefix' as you can see here http://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Util.html#Ext-app-Util
[update] So one thing that can be done is to override the static method resolveNamespace like this:
statics: {
resolveNamespace: function(cls, data) {
var Controller = Ext.app.Controller,
namespaceRe = cls.prototype.isProfile ? Controller.profileRegex : Controller.controllerRegex,
className, namespace, match;
/*
* Namespace resolution is tricky business: we should know what namespace
* this Controller descendant belongs to, or model/store/view dependency
* resolution will be either ambiguous or plainly not possible. To avoid
* guessing games we try to look for a forward hint ($namespace) that
* Application class sets when its onClassExtended gets processed; if that
* fails we try to deduce namespace from class name.
*
* Note that for Ext.app.Application, Controller.onClassExtended gets executed
* *before* Application.onClassExtended so we have to delay namespace handling
* until after Application.onClassExtended kicks in, hence it is done in this hook.
*/
className = Ext.getClassName(cls);
namespace = data.$namespace || data.namespace ||
Ext.app.getNamespace(className) ||
((match = namespaceRe.exec(className)) && match[1]);
//<debug>
if (!namespace) {
Ext.log.warn("Missing namespace for " + className + ", please define it "+
"in namespaces property of your Application class.");
}
//</debug>
//This is the only change on this override.
//http://stackoverflow.com/questions/37731213/extjs-6-stores-config-on-ext-app-controller-not-working/37733261#37733261
if(namespace && namespace.indexOf(".controller") > -1) {
namespace = namespace.slice(0, namespace.indexOf(".controller"));
}
return namespace;
}
}
If you know of a better solution please let me know!
这篇关于ExtJs 6存储在Ext.app.Controller上的配置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!