EXT JS 5 - 重写ViewController定义? [英] EXT JS 5 - Override ViewController definition?

查看:111
本文介绍了EXT JS 5 - 重写ViewController定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让所有的ViewControllers有两个自定义的方法。



我试图通过创建一个类扩展从 ViewController ,调用 CustomViewController ,然后让我的其他ViewControllers扩展我的 CustomViewController 类,在控制台中显示警告消息:

  [W]覆盖现有映射:'controller.login'从'MyApp.view .mybutton.MyButtonController'到'MyApp.view.override.CustomViewController'。这是故意吗? 

我测试的组件甚至没有加载。



我意识到我可以直接从ext-all-debug.js库,它在我的应用程序的根文件夹中的 ext 文件夹,当我使用Sencha CMD来构建应用程序时,它将使用我的工作区中的原始库,而不是我在应用程序的文件夹中的那个,所以我的更改只会在开发时工作,不会继续生产。 / p>

这样做的正确方法是什么?是否有标准?

解决方案

这个错误可能意味着你有同样的别名 config on Eathisa.view.login.loginController Eathisa.view.override.EathisaViewController



根据你所描述的内容,当你尝试以别名使用它时,会有一些歧义。它不听起来像你需要一个覆盖。如果你需要在所有的ViewController中有一些方法,你可以将它们添加到一个自定义的ViewController,然后将其作为应用程序中所有其他ViewController的基础,而不是 Ext.app.ViewController

  Ext.define('Eathisa.view.AbstractViewController',{
extend: Ext.app.ViewController',
//注意,这里没有alias属性,所以
//这个抽象VC不能由别名实例化

//你甚至可以通过将它们包含在< debug>< / debug>
//中,从
//生产构建中排除这些自定义方法:
//< debug>
methodFoo:function(){
...
}
//< / debug>
}

Ext.define('Eathisa.view.login.LoginController',{
extend:'Eathisa.view.AbstractViewController',
alias:'controller.login',

methodThatUsesFoo:function(){
//只是不要忘记在同一个< debug>括号中包含*调用*
//调试方法
//< debug>
this.methodFoo();
//< / debug>

...
} $ b b});

如果从同一抽象VC扩展所有ViewController不可行, mixin代替,并将该mixin包含在需要调试方法的VC中:

  Ext.define('Eathisa.mixin.Debug' ,{
methodFoo:function(){
...
}
});

Ext.define('Eathisa.view.login.LoginController',{
extend:'Ext.app.ViewController',
别名:'controller.login',

//有条件地包含调试mixin
//< debug>
mixins:[
'Eathisa.mixin.Debug'
],
//< / debug>

...
});


I want all my ViewControllers to have two custom methods.

I tried to accomplish this by creating a class that extends from the ViewController, called CustomViewController, and then having my other ViewControllers extend my CustomViewController class, but then I get a warning message in the console saying:

[W] Overriding existing mapping: 'controller.login' From 'MyApp.view.mybutton.MyButtonController' to 'MyApp.view.override.CustomViewController'. Is this intentional?

And the component I tested it with didn't even load.

I realize I could do this straight from the ext-all-debug.js library that's inside the ext folder in my app's root folder, but then when I use Sencha CMD to build the app it'll use my original library that's in my workspace, and not the one I have in my app's folder, so my changes will only work while developing and won't carry on to production.

What's the proper way of doing this? Is there a standard?

解决方案

That error probably means that you have the same alias config on both Eathisa.view.login.loginController and Eathisa.view.override.EathisaViewController. There will be some ambiguity as to which class to load when you try to use it by an alias, that is why the class system is warning you.

From what you describe it doesn't sound like you need an override at all. If you need to have some methods in all your ViewControllers, you can add them in a custom ViewController and then use it as a base for all other ViewControllers in your application, instead of 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>

        ...
    }
});

If it's not feasible to extend all your ViewControllers from the same abstract VC, implement the custom methods in a mixin instead, and include that mixin in the VCs that need debug methods:

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>

    ...
});

这篇关于EXT JS 5 - 重写ViewController定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆