PDA

View Full Version : Params to constructor/init of an extended class?



jvolt
21 May 2010, 7:30 AM
How to pass params to a Extended class?
i.e


MyWindow = Ext.extend(Ext.Window, {
title: 'My Window ' + param1,
initComponent: function() {
this.items = [
{
xtype: 'panel',
html: param2
}
}
});

Because i need use that params when create a new window...

CrazyEnigma
21 May 2010, 12:59 PM
constructor: function(config) {
config = config || {};
// Your config are the parameters that you pass.
Ext.apply(this, config);
MyWindow.superclass.constructor.call(this);
}

jvolt
24 May 2010, 6:05 AM
Thanks very much CrazyEnigma =D

I don't understand what "config = config || {};" does tho

steffenk
24 May 2010, 7:37 AM
config is config or (if not exists) an empty object. Such expression is needed so config isn't undefined.

It's a shorter form of


config = config !== 'undefined' ? config : {};

jvolt
24 May 2010, 7:46 AM
Oh Thanks steffenk =D

Very useful!

jvolt
28 May 2010, 12:33 PM
[SOLVED]
Hello again guys,

I've tried that but got an error.



adicionarBonus = Ext.extend(adicionarBonusUi, {
constructor: function(cfg) {
cfg = cfg || {};
adicionarBonus.superclass.constructor.call(this, Ext.apply(this, cfg));
},
initComponent: function() {
adicionarBonus.superclass.initComponent.call(this);
}
});


Firebug show the error:
h.directCfg is undefined =(

That is an extended window with a grid (the grid uses a directfn, i will do that to populate the grid using a param from the constructor)


SOLVED. The problem was on Ext Designer Expor, if you has got same problem look here:

http://www.extjs.com/forum/showthread.php?99295-3.2.1-DirectStore-and-Designer-directFn.directCfg-undefined&highlight=DirectCfg