0

コードを正しく実装する最善の方法について質問があります。

私は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経由で試しましたが、この設定を必要とする他のファイルは前にロードされています...

誰かが手がかりを持っているなら。

良い一日を過ごしてください !

4

1 に答える 1

0

Ext.requireを使用する場合は、 Ext.onReadyリスナー内でアプリケーションを作成する必要があります。

Ext.require('MyApp.configuration.elastic');

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

または、アプリケーションのメイン クラスに構成クラスが必要になるため、これも機能するはずです。

Ext.define('MyApp.Application', {
    requires: ['MyApp.configuration.elastic'],
    // ...
});
于 2013-11-05T14:54:36.187 に答える