javascript - Sencha Touch 2 全局变量 - 随处访问

标签 javascript cordova global-variables sencha-touch-2

我知道这个问题已经发布在 StackOverflow 中,但我要么不明白,要么 sencha 有所改变。

我的应用程序加载一个用于登录的表单面板,然后我想保存刚刚登录的用户信息。这样我就可以随时更改 View ,并且仍然知道登录用户的名称。

这是我的主要代码:

//<debug>
Ext.Loader.setPath({
    'Ext': 'sdk/src'
});

//</debug>
Ext.application({
    name: 'APP',

    loadedUser: 'the test',

    requires: ['Ext.MessageBox'],

    views: ['Main', 'Home', 'Login'],

    models: ['User'],

    stores: ['Users'],

    controllers: ['Main'],

    icon: {
        57: 'resources/icons/Icon.png',
        72: 'resources/icons/Icon~ipad.png',
        114: 'resources/icons/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fcb59f9392bcce84d28c929b" rel="noreferrer noopener nofollow">[email protected]</a>',
        144: 'resources/icons/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b2208040515021b0a0f2b5913451b050c" rel="noreferrer noopener nofollow">[email protected]</a>'
    },

    phoneStartupScreen: 'resources/loading/Homescreen.jpg',
    tabletStartupScreen: 'resources/loading/Homescreen~ipad.jpg',

    setLoadedUser: function(arg) {
        this.loadedUser = arg;
    },

    launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();

        // Initialize the main view
        Ext.Viewport.add(Ext.create('APP.view.Main'));
    },

    onUpdated: function() {
        Ext.Msg.confirm("Application Update", "This application has just successfully been updated to the latest version. Reload now?", function() {
            window.location.reload();
        });
    }
});

“loadedUser”是我想要的全局变量,setLoadedUser(arg) 方法应该更改该值。

我可以毫无问题地访问“loadedUser”,但无法更改其值。 另一个问题:loadedUser可以是数组/数据结构吗?

最佳答案

您如何访问该功能?这对我有用。请记住,您应该像这样访问它:

APP.app.setLoadedUser('test');

是的,它可以是任何值。 :)

关于javascript - Sencha Touch 2 全局变量 - 随处访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9886363/

相关文章:

cordova - 如何在 PhoneGap 应用程序中缓存千兆字节(大量)本地数据?

sqlite - webkit 中的 sqlite 是否支持 RANDOM() 函数?

c - freeRTOS环境下公共(public)变量的存储区

python - 从 Process() 设置时,全局变量无法正确保存

javascript - 将 jQuery 集合拆分为单个 jQuery 对象的数组

javascript - 简单的幻灯片第一张幻灯片完全淡出

javascript - 选择 nicEdit 中的元素

Javascript 警报不适用于按钮单击

javascript - Phonegap 文件 API 未返回正确路径仅​​返回 '/'

c++ - C/C++ - 推荐使用 const static 还是 #define