ExtJS4:从Ext.Application访问全局变量
我想加载一些特定于应用程序的设置,并在加载应用程序时将其保存为全局变量。我发现了如何创建和访问全局变量 这就是我的ExtJS4:从Ext.Application访问全局变量,extjs,extjs4,Extjs,Extjs4,我想加载一些特定于应用程序的设置,并在加载应用程序时将其保存为全局变量。我发现了如何创建和访问全局变量 这就是我的app.js的样子: Ext.application({ stores: [ ... ], views: [ ... ], autoCreateViewport: true, name: 'MyApp', controllers: [ 'DefaultController'
app.js
的样子:
Ext.application({
stores: [
...
],
views: [
...
],
autoCreateViewport: true,
name: 'MyApp',
controllers: [
'DefaultController'
],
launch: function() {
...
}
});
是否可以在
launch:function()
block中设置这些变量?如果没有,还有其他选择吗?您也可以创建一个单例:
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.
}
});
我刚刚发现了这一点,你及时发布了:)此外,它也可以在没有单例的情况下工作。感谢是的,但是如果你
Ext.ceate()
一个带有singleton:true
的类,你就不会有新的实例,所以使用它更安全。为什么我不能在商店中访问myGlobal?