Hi !!!!!
How to use global variables in ExtJs 4. please give an example.
Thank you.
Hi !!!!!
How to use global variables in ExtJs 4. please give an example.
Thank you.
Globals! Generally a bad idea.
If I were you I'd wrap up the variables I needed to share in a singleton.
Can then access using MySharedData.foo, for instance.PHP Code:
Ext.define('MySharedData', {
singleton: true,
foo: 'bar',
meh: 42
});
HTH,
Westy
Product Architect
Altus Ltd.
Mitchell Simoens @LikelyMitch
Modus Create, Senior Frontend Engineer
________________
Need any sort of Ext JS help? Modus Create is here to help!
Check out my GitHub:
https://github.com/mitchellsimoens
Hi,
I would use this way to manage global variables but i have a problem with store definition.
My global variables definition :
I add Requires in my Ext.application :PHP Code:
Ext.define('EM.Global', {
singleton: true,
urlGetData: 'server/getData.php',
imgLogoSite: 'obj/images/site/logo.gif'
});
I can use EM.Global.imgLogoSite in a View and it's ok.PHP Code:
Ext.application({
requires: ['EM.Global',
'Ext.container.Viewport'],
name: 'EM',
appFolder: 'app',
autoCreateViewport: true,
(...)
But when i add in Ext.application store which use EM.Global.urlGetData for the url config, i have an error : EM is not defined (in Firefox):
And in Store :PHP Code:
Ext.application({
requires: ['EM.Global',
'Ext.container.Viewport'],
name: 'EM',
appFolder: 'app',
autoCreateViewport: true,
stores: ['Users'],
(...)
I don't undestand where is my mistake.PHP Code:
Ext.define('EM.store.Users', {
extend: 'Ext.data.Store',
requires: ['EM.Global',
'EM.model.User'],
model: 'EM.model.User',
proxy:{
type:'ajax',
url: EM.Global.urlGetData,
reader: {
(...)
Thank you for your help.
LaZag
(ExtJS 4.1.1a)
The line:
is being evaluated before Ext.define is called.Code:url: EM.Global.urlGetData,
Keep in mind that Ext.define is just a JavaScript function. The second argument passed to that function is an anonymous JavaScript object describing the class.
It is effectively equivalent to the following:
The requires block never gets a chance.Code:var config = { ... proxy:{ url: EM.Global.urlGetData, ... } }; Ext.define('EM.store.Users', config);
The simplest solution is just to make sure your globals get loaded first, maybe using a script tag. A more painful alternative is to move parts of the class definition into a callback function (third argument of Ext.define).
Product Architect
Altus Ltd.
Can you please elaborate it with your above code?
Something like:
We use this trick where a class requires another class in its actual definition.Code:Ext.require([ 'EM.Global' ], function() { Ext.define('EM.store.Users', { extend: 'Ext.data.Store', requires: ['EM.Global', 'EM.model.User'], model: 'EM.model.User', proxy:{ type:'ajax', url: EM.Global.urlGetData, reader: { (...) });
It should be avoided if possible, but can be used when necessary.
Another way would be to define your proxy in the constructor, since requires will be loaded before a method is callable.
Product Architect
Altus Ltd.