My goal is to share a config property lang of class User with all instances of this class. lang will hold an instance of a translation class Language, that will once async load data.
The problem is I cannot get the callback in the config to call a function of the instance.
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' ) );
...
}
How can I get that to work? Is there a better design for this case?
Callback invoking:
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();
}