PDA

View Full Version : Extjs extending a class, public private members.



muncher
14 Jul 2010, 5:01 PM
Below is the code snippet that I am using to extend a combobox. What I want to do is able to take the url for datastore as input and initialize it in the constructor.

i.e var tmp = new Ext.xx.form.CombBox({'url':'eeee'});
something like that.



Ext.xx.form.ComboBox = Ext.extend(Ext.form.ComboBox, {
initComponent: function(config) {
Ext.apply(this, {
// id: 'ggCombo',
store: new Ext.data.Store({
//url: config.url,
reader: new Ext.data.XmlReader({
// records will have a 'plant' tag
record: 'qq',
// use an Array of field definition objects to implicitly
// create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except
// 'availDate'
// which is mapped to the tag 'availability'
{name: 'ff', type: 'string'},
{name: 'rr', type: 'string'}
]
})
}),
displayField: 'rr',
valueField: 'ff',
hiddenName : 'trtr',
typeAhead: true,
mode: 'local',
fieldLabel: 'TrTr',
anchor: '100%',
forceSelection: true,
triggerAction: 'all',
emptyText:'Select a trtr...',
selectOnFocus:true
});

Ext.xx.form.ComboBox.superclass.initComponent.apply(this);
}

});

evant
14 Jul 2010, 5:32 PM
All options passed into the config are automatically applied to the component. So by the time you get to initComponent, this.url is already equal to 'eeee'.

muncher
14 Jul 2010, 5:34 PM
right. But my this is the combobox. I want to set the url of the store inside the combobox.

evant
14 Jul 2010, 5:57 PM
As I said, you already have a reference to it, so:



new Ext.data.XmlStore({
url: this.url
//.....
})

muncher
14 Jul 2010, 6:27 PM
cool, thanks.

muncher
15 Jul 2010, 10:43 AM
How do I keep default values for such a class and override those if they are provided in input.

For example the width field, if the config has something like 'width':'100', it should assign value to the width field or else initialize it to some default value.

muncher
15 Jul 2010, 2:26 PM
*bump*

Animal
15 Jul 2010, 11:42 PM
Apply the config to an object containing your defaults



constructor: function(config) {
config = Ext.apply({
width: 100,
otherDefaultConfig: 'the default value',
...
}, config);
// call superclass passing the config....
}