Using Global variables and arrays in Extjs 4

This example will show you how to declare a global var and arrays in Extjs MVC application.

You know where to find this code :

<script type="text/javascript">
        Ext.BLANK_IMAGE_URL = '/Content/images/default/s.gif';
</script>

Global application variable :

<script type="text/javascript">
        Ext.BLANK_IMAGE_URL = '/Content/images/default/s.gif';
        Ext.MY_GLOBAL_VAR = '<?php echo $myGlobalVar; ?>'; 
</script>

Simple, right? Now you can access this variable everywhere in your mvc application.

Ext.define('PG.store.Dir', { 
	extend: 'Ext.data.TreeStore', 
	proxy: {
		type: 'ajax',
		url: 'http://'+Ext.MY_GLOBAL_VAR+'/getFolder.php'
	}
});

If you need arrays , try this:

<script type="text/javascript">
        Ext.BLANK_IMAGE_URL = '/Content/images/default/s.gif';
        Ext.MY_GLOBAL_VAR_ARRAY = [ 1, 2, 3, [ 'a', 'b', 'c' ] ]; 
</script>
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

3 Responses to “Using Global variables and arrays in Extjs 4”

  • ttt says:

    are you crasy! global VAR’s since ext 1 to ext 4 never need its a dummy practice

  • AUH says:

    Exactly what I was looking for. Yes I can define singleton class and put my global vars there but sometime you need simple solution for simple problem. I needed to set value of couple of JavaScript vars from Coldfusion and did not want to go though defining class and using Ajax request to initialize vars.

  • Actually no matter if someone doesn’t understand afterward its up to other users that they will assist, so here it occurs.

  • Leave a Reply:

    Name (required):
    Mail (will not be published) (required):
    Website:
    Comment (required):
    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>