2013-04-24 3 views
3

일부 응용 프로그램 특정 설정을로드하고 응용 프로그램로드시 전역 변수로 저장하려고합니다. 전역 변수 here을 만들고 액세스하는 방법을 찾았습니다.ExtJS4 : Ext.Application에서 전역 변수에 액세스

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

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

launch: function() 블록 내에서 이러한 변수를 설정할 수 있습니다 :

이 내 app.js의 모습을 어떻게? 그렇지 않다면 대안이 있습니까?

당신은 또한 싱글 만들 수 있습니다

답변

6

: 앱에서

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

을 :) 은 또한 그것은 singleton'도'없이 작동 . 감사! – vahissan

+3

그래,하지만 클래스를'singleton : true'로'Ext.ceate()'하면 새 인스턴스가 없으므로 사용하는 것이 더 안전합니다. –

+0

상점에서 myGlobal에 액세스 할 수없는 이유는 무엇입니까? –

관련 문제