Beruflich Dokumente
Kultur Dokumente
com/learn/Tutorial:Extending_Ext_for_Newbies
PERSONAL TOOLS
Log in / create account
Register
function createMyPanel(config) {
return new Ext.Panel(Ext.apply({//Pre-configured config options go here
width: 300,
height: 300
}, config));
};
Extending Functionality
Another reason you want to use OO classes is that you want to extend the functionality of another class. Let us say you want to add
a function in the above panel and override an existing function. This is one way to do it:
// Constructor
var MyPanel = function(config) {
//Reusable config options here
Ext.apply(this, {
width: 300,
height: 300
});
// And Call the superclass to preserve baseclass functionality
1 of 3 11/8/10 11:11 AM
Tutorial:Extending Ext for Newbies - Sencha - Learn http://www.sencha.com/learn/Tutorial:Extending_Ext_for_Newbies
MyPanel.superclass.constructor.apply(this, arguments);
// Here you can add functionality that requires the object to exist, Home Products Support ©
// like event handling.
this.on('click', function() {alert("You Clicked " + this.title);}, this); Training Job Board Company
};
Contact Blog Store Privacy
// MyPanel Extends Ext.Panel
Ext.extend(MyPanel, Ext.Panel, { 2006-2010 Sencha Inc.
// Here you can add static variables for the class. variables that will have
// the same value for all object instances of this class.
// If you are not sure put it in the constructor above. Dont put any abject
// created with 'new' or 'xtype' here. You are safer putting it in the config
// option in the constructor.
The preferred way to handle event handling (listeners) is to add them after the call to the superclass in the constructor or
initComponent.
MyPanel.superclass.constructor.apply(this, arguments);
// Here you can add functionality that requires the object to exist,
// like event handling.
2 of 3 11/8/10 11:11 AM
Tutorial:Extending Ext for Newbies - Sencha - Learn http://www.sencha.com/learn/Tutorial:Extending_Ext_for_Newbies
this.on(
'click',
function() {
alert("You Clicked " + this.title);
},
this
);
In the case of the factory method you would add a event handler outside of the factory method like this.
myFirstPanel.on(
'click',
function() {
alert("You Clicked " + this.title);
},
myFirstPanel //scope
);
There are other ways of handling listeners notably by adding a listeners config option. But I would recommend that to advanced
users.
There are many ways of doing the same thing in Ext JS. If you are spoiled for choice on which way to go, choose the one you are
most comfortable with.
Further Reading:
1) Creating new UI controls
2) Saki's Tutorial: Extending Ext Class
3) mjlecomte's Sticky on Extending Ext Class
4) Discussion on this Tutorial
________________
VIEWS
Tutorial
Discussion
View source
History
3 of 3 11/8/10 11:11 AM