ExtJS4:从Ext.Application访问全局变量 [英] ExtJS4: Accessing global variables from Ext.Application

查看:657
本文介绍了ExtJS4:从Ext.Application访问全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载一些应用程序特定的设置,并在加载应用程序时将其保存为全局变量。我已经找到了如何创建和访问全局变量 here

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.

这是我的 app.js 如下所示:

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

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

可以在中启动这些变量:function()块?如果没有,是否有其他选择?

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

推荐答案

您还可以创建一个单例:

You can also create a singleton:

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

     myGlobal: 1
});

在您的应用程序中:

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.
    }
});

这篇关于ExtJS4:从Ext.Application访问全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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