我的目标是与lang
该类User
的所有实例共享类的配置属性。lang
将保存一个翻译类的实例,该实例Language
将异步加载数据。
问题是我无法在配置中获取回调来调用实例的函数。
Ext.define( 'X.User.controller.Main', {
extend: 'Deft.mvc.ViewController',
config: {
// create one Language instance once for all User instances
lang: Ext.create( 'X.Language.Main', {
loaded: false,
language: 'de',
// this callback gets called correctly after loading language resources
callback: function() {
// ERROR since "this" is window, not the User instance
this.lang.loaded = true; // should mark it loaded for next instances
this.start(); // should start the instance logic
}
} )
},
init: function() {
var that = this;
if( that.lang && that.lang.loaded )
{
that.start();
}
},
start: function() {
// use the translation functions...
oView.setLoading( that.lang.get( 'checkingPrivileges' ) );
...
}
我怎样才能让它工作?这种情况有更好的设计吗?
回调调用:
constructor: function( oConfig ) {
var that = this;
that.getLanguageFile( oConfig );
that.initConfig( oConfig );
}
getLanguageFile: function( oConfig ) {
var fCallback = oConfig.callback || Ext.emptyFn;
...
// in my ajax success function...
fCallback();
}