【问题标题】:Launch code before Application creation and requirement在应用程序创建和需求之前启动代码
【发布时间】:2013-11-16 11:10:27
【问题描述】:

我对正确实现我的代码的最佳方式有疑问。

我在 app.js 中有这个

/*** EXT LOADER ENABLE & PATH                       ***/
Ext.Loader.setConfig(
{
    enabled             : true,
    application         : 'MyApp'
});

Ext.log('--- APPLICATION --- Loading Elasticsearch configuration');
Ext.define('MyApp.configuration.elastic',
{
    singleton   : true,
    ...
    loadElasticConfiguration: function()
    {
        // ExtDirect or ajax call in order to set configuration
    }
});
MyApp.configuration.elastic.loadElasticConfiguration();

Ext.onReady(function()
{});

Ext.create('MyApp.Application');

这很好,但我不喜欢有很多代码是 app.js。 有没有办法将“MyApp.configuration.elastic”代码“导出”到特定文件并调用它。我已经通过 Ext.require 尝试过,但其他需要此配置的文件在之前加载...

如果有人有线索。

祝你有美好的一天!

【问题讨论】:

    标签: extjs launch onbeforeload


    【解决方案1】:

    如果您想使用Ext.require,您需要在Ext.onReady 监听器中创建您的应用程序:

    Ext.require('MyApp.configuration.elastic');
    
    Ext.onReady(function(){
        Ext.create('MyApp.Application');
    });
    

    另外,这也应该起作用,因为它会使您的应用程序的主类需要配置类:

    Ext.define('MyApp.Application', {
        requires: ['MyApp.configuration.elastic'],
        // ...
    });
    

    【讨论】:

    • 我真是个白痴。当然,我可以这样做。我为其他人做过谢谢,我为这个新手问题道歉。
    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 2021-08-11
    • 2014-10-13
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2019-11-18
    相关资源
    最近更新 更多