문제

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?

도움이 되었습니까?

해결책

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;
}

다른 팁

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'
      }
   });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top