Cra*_*mps 3 javascript inheritance extjs class
我希望我的所有ViewControllers都有两个自定义方法.
我尝试通过创建一个扩展自ViewController,调用CustomViewController,然后让我的其他ViewControllers扩展我的CustomViewController类的类来完成此操作,但随后我在控制台中收到一条警告消息:
[W] Overriding existing mapping: 'controller.login' From 'MyApp.view.mybutton.MyButtonController' to 'MyApp.view.override.CustomViewController'. Is this intentional?
Run Code Online (Sandbox Code Playgroud)
我测试的组件甚至没有加载.
我意识到我可以直接从ext我的应用程序根文件夹中的文件夹内的ext-all-debug.js库中执行此操作,但是当我使用Sencha CMD构建应用程序时,它将使用我工作区中的原始库,而不是我在我的应用程序文件夹中的那个,所以我的更改只会在开发时工作,不会继续生产.
这样做的正确方法是什么?有标准吗?
该错误可能意味着你有相同的alias两个配置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>
...
}
});
Run Code Online (Sandbox Code Playgroud)
如果从同一个抽象VC扩展所有ViewController是不可行的,那么在mixin中实现自定义方法,并将mixin包含在需要调试方法的VC中:
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>
...
});
Run Code Online (Sandbox Code Playgroud)