gpt4 book ai didi

javascript - ExtJs 6 在 Ext.app.Controller 上存储配置不工作

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

我刚刚注意到存储配置 http://docs.sencha.com/extjs/6.0/6.0.2-classic/#!/api/Ext.app.Controller-cfg-stores在 Ext.app.Controller 上不看在正确的路径中(与 View 配置相同)。

例如

Ext.define('MyApp.controller.Menu', {
extend: 'Ext.app.Controller',
stores: ['Menu']
...
});

这将寻找

http://localhost/myapp/app/controller/store/Menu.js?_dc=20160607211025

注意 Controller 文件夹

代替

http://localhost/myapp/app/store/Menu.js?_dc=20160607211025

一开始我以为这是我的一个项目特有的配置问题,但后来在另一个项目上得到了同样的结果。

我正在使用 ExtJs 6.02

我知道我可以使用完整的类名,例如 MyApp.store.Menu,但那样的话 getter 会非常难看。 (这发生在我刚刚升级的庞大代码库上,因此使用完整的类名将是我最后的资源)。

有人遇到过这个问题吗?

最佳答案

我找到了原因(耐心等待):

https://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Controller2.html#Ext-app-Controller

看:

onClassExtended -> Controller.resolveNamespace -> Ext.app.getNamespace

那些是重要的,一旦命名空间被解析,就会调用进程依赖:

Controller.processDependencies(proto, requires, namespace, 'store', data.stores);

我对此进行了研究,Ext.app.getNamespace 在 ext 5 和 6 中是相同的

那么为什么它在 ExtJs 5 中

Ext.getNamespace("MyApp.controller.SomeController");//返回 MyApp

和 ExtJs 6

Ext.getNamespace("MyApp.controller.SomeController");//返回 MyApp.controller

原因是通过 console.log Ext.ClassManager.paths 找到的,现在有一个新条目对应于 MyApp.controller

enter image description here

之前MyApp.controller(ZHT.controller)没有key

Ext.getNameSpace 所做的是寻找“最深前缀”,如您在此处所见http://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Util.html#Ext-app-Util

[更新]所以可以做的一件事是重写静态方法 resolveNamespace,如下所示:

  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;
}
}

如果您知道更好的解决方案,请告诉我!

关于javascript - ExtJs 6 在 Ext.app.Controller 上存储配置不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37731213/

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