3

I want to load some application specific settings and save them as global variables when the application is loaded. I have found how to create and access global variable here.

This is how my app.js looks like:

Ext.application({
    stores: [
        ...
    ],
    views: [
        ...
    ],
    autoCreateViewport: true,
    name: 'MyApp',
    controllers: [
        'DefaultController'
    ],

    launch: function() {
        ...
    }
});

Is it possible to set these variables inside launch: function() block? If not, are there any alternatives?

4

1 回答 1

6

You can also create a singleton:

Ext.define('MyApp.util.Utilities', {
     singleton: true,

     myGlobal: 1
});

in your app:

Ext.application({
    stores: [
        ...
    ],
    views: [
        ...
    ],
    autoCreateViewport: true,
    name: 'MyApp',
    controllers: [
        'DefaultController'
    ],

    requires: ['MyApp.util.Utilities'], //Don't forget to require your class

    launch: function() {
        MyApp.util.Utilities.myGlobal = 2; //variables in singleton are auto static.
    }
});
于 2013-04-24T08:41:08.180 回答