我希望我的所有ViewControllers都有两个自定义方法.
我尝试通过创建一个从ViewController扩展的类(称为CustomViewController),然后让我的其他ViewControllers扩展我的CustomViewController类来完成此操作,但后来我在控制台中收到一条警告消息:
[W] Overriding existing mapping: 'controller.login' From 'MyApp.view.mybutton.MyButtonController' to 'MyApp.view.override.CustomViewController'. Is this intentional?
我测试的组件甚至没有加载.
我知道我可以直接从我的应用程序根文件夹中的ext文件夹内的ext-all-debug.js库中执行此操作,但是当我使用Sencha CMD构建应用程序时,它将使用我工作区中的原始库,而不是我在我的应用程序文件夹中的那个,所以我的更改只会在开发时工作,不会继续生产.
这样做的正确方法是什么?有标准吗?
解决方法:
该错误可能意味着您在Eathisa.view.login.loginController和Eathisa.view.override.EathisaViewController上具有相同的别名配置.当您尝试通过别名使用它时,将会加载哪个类,这就是类系统警告您的原因.
根据你的描述,听起来并不像你需要覆盖.如果您需要在所有ViewControllers中都有一些方法,可以将它们添加到自定义viewController中,然后将其用作应用程序中所有其他ViewControllers的基础,而不是Ext.app.ViewController:
Ext.define('Eathisa.view.AbstractViewController', {
extend: 'Ext.app.ViewController',
// Note that there is no "alias" property here, so that
// this abstract VC can't be instantiated by alias
// You can even make these custom methods excluded from
// production build by enclosing them in the <debug></debug>
// comment brakets:
//<debug>
methodFoo: function() {
...
}
//</debug>
});
Ext.define('Eathisa.view.login.LoginController', {
extend: 'Eathisa.view.AbstractViewController',
alias: 'controller.login',
methodThatUsesFoo: function() {
// Just don't forget to enclose the code that *calls*
// debug-only methods in the same <debug> brackets
//<debug>
this.methodFoo();
//</debug>
...
}
});
如果从同一个抽象VC扩展所有ViewController是不可行的,那么在mixin中实现自定义方法,并在需要调试方法的VC中包含mixin:
Ext.define('Eathisa.mixin.Debug', {
methodFoo: function() {
...
}
});
Ext.define('Eathisa.view.login.LoginController', {
extend: 'Ext.app.ViewController',
alias: 'controller.login',
// Conditionally include the debugging mixin
//<debug>
mixins: [
'Eathisa.mixin.Debug'
],
//</debug>
...
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。