In ExtJS 6.2, does subclasses inherit the parent config?
It doesn't seem to work for me.
Ext.define('test1', {
config: {
test1: {
test1: ''
}
},
constructor(config) {
Ext.apply(this, config);
console.log(config);
},
});
Ext.define('test2', {
extend: 'test1',
config: {
test2: ''
},
constructor(config) {
this.callParent(config);
console.log(this.config);
},
});
Ext.create('test2', {
test1: {
test1: 'test1'
},
test2: 'test2'
});
Also it seems that on parent constructor config
is undefined
!
I want to have everything defined on parent class config also available in child class. And be able to set parent config when creating child class.
Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/3fud
CodePudding user response:
You have to initConfig to get the ExtJS typical configs. You get all configs inside test2.
Ext.define('test1', {
config: {
test1: null
},
constructor(config) {
this.initConfig(config);
return this;
}
});
Ext.define('test2', {
extend: 'test1',
config: {
test2: ''
},
constructor(config) {
// == > config
this.callParent([config]);
// ==> her you can even use getTest1(), setTest1() (or test2)
}
});
Ext.create('test2', {
test1: {
test1: 'test1'
},
test2: 'test2'
});
CodePudding user response:
One workaround is to call Ext.apply(this, config);
not sure if this is the correct solution.
Ext.define('test2', {
extend: 'test1',
config: {
test2: ''
},
constructor(config) {
this.callParent(config);
Ext.apply(this, config); // <-
console.log(this.config);
console.log(this.getTest1());
console.log(this.getTest2());
},
});