我知道这个问题已经发布在 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/