Question

i have something like

Ext.define('HS.controller.Utility', {
  statics : {
    state : 'Oklahoma'
     }
  });

Now i want to access it from my controllers, but in every method of controller, i have to write HS.controller.Utility.state to access it. currently i'm doing this : var ut = HS.controller.Utility and then accessing state as ut.state, but again, i've to declare this variable in every function. Is there a way to set it to a short name once in my controller and then access from all functions?

Était-ce utile?

La solution

There are several ways you could do it, the best of which:

// Becomes a global variable
var X = Ext.define('My.long.class.Name');

// Set a reference on your main NS at launch time
launch: function() {
    MyApp.X = My.long.class.Name;
}

Autres conseils

Even easier than the current answer is to just declare an alternateClassName with no namespace. Only one line of code, no initialization or race conditions, built into ExtJs.

Ext.define('HS.controller.Utility', {

   //
   // Non-namespaced alternate class name will create 
   // 'globally defined' Utility object.
   //
   alternateClassName: 'Utility',

   statics : {
         state : 'Oklahoma'
      }
   });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top