1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    17
    Vote Rating
    0
    marco1991 is on a distinguished road

      0  

    Default Unanswered: static variables in sencha touch

    Unanswered: static variables in sencha touch


    hi!

    when I open my app I have to do a login.. I do it and it is perfect…
    (is a very easy login, no password is required..only a username)

    in the others view I always put a toolBar where i want to display that username..

    i tried to do this in the Controllers but i have a lot of views and i would prefer something easier, like a static varaible in java

    something like:
    Code:
    	
    
    //IN LOGIN VIEW:
    Settings.setCurrentUser(field.getValue())...
    
    //IN ALL THE OTHERS VIEWS:
    label.setHtml(Settings.getCurrentUser())...
    thanks!

  2. #2
    Sencha Premium Member
    Join Date
    Feb 2010
    Location
    Chicago
    Posts
    20
    Vote Rating
    1
    Answers
    7
    Johnny Major is on a distinguished road

      0  

    Default


    You could create a class that has the needed config options. Then use the getters / setters.

    Code:
    Ext.define('YourApplication.config.Runtime',{
        singleton : true,
        config : {
            currentUser : null
        },
        constructor : function(config){
            this.initConfig(config);
        }
    });
    Set/Get the current user
    Code:
    var runtime = YourApplication.config.Runtime,
          currentUsr;
    
    runtime.setCurrentUser('Tom');
    currentUsr = runtime.getCurrentUser();
    Take a look at Ext.Class via the documents.