Tutorial: xtype defined (Chinese) from learn about the ext JavaScript libraryjump to: navigation, search
Summary:This tutorial explains howXtype. |
Author:Jozef sakalos (TRANSLATOR: Frank Cheung) |
Published:2008 may May 9 |
EXT version:2.0 + |
Ages: EnglishChinese |
Contents [Hide]
- 1 Preface
- 2 Definition
- 3 What are the benefits?
- 4 Delayed instantiation
- 5 Further reading
|
Preface
According to my observations on the ext Forum, there are many questions when xtype is used. Some people even ignore xtype, or do not know what it is. So I decided to elaborate on this xtype concept.
Definition
XtypeIs an identifier that represents a class.
For example, you have this class namedExt. UX. mygrid
. Normally, you need to use this name to instantiate the class (create the class object ).
In addition to the class name, you can registerXtype:
Ext.Reg('Mygrid', Ext.UX.Mygrid);
WhereXtypeYesMygrid
The general form of the class name isExt. UX. mygrid
. The preceding statementRegisteredNewXtypeIn other words,XtypeMygrid
And classExt. UX. mygrid
Is connected together.
What are the benefits?
Imagine that you are working on a large project. To respond to user operations,ProgramContains a large number of objects (Windows, forms, grids ). When you click the icon or button, a new form is created. The form contains a grid, which is rendered on the screen.
Well, we went back to the code before ext2.x. At that time, we instantiated all objects after the page was loaded for the first time (the programCodeFirst run ). In the client memory,Ext. UX. mygrid
Class Object already exists, waiting for the user to click. This is also the grid. Suppose you have hundreds of instances. How a waste of valuable resources! Many grid users may not click to make it appear.
Delayed instantiation
If you useXtypeIn the memory, it is only a configuration item object, such:
{Xtype:'Mygrid ", border: false, width: 600, height: 400 ,...}
There is no complex instance object to consume.
Well, what if a user clicks a button or icon? EXT identifies it as a grid to be rendered but does not instantiate it immediately. Ext understands this with the help of componentmgr: "If I want to instantiateXtypeMygrid
Object, I know the actual class to be createdExt. UX. mygrid
". The following code is used:
Create:Function(Config, defaulttype){Return NewTypes[Config.Xtype| Defaulttype](Config);}
It is equivalent:
Return NewExt.UX.Mygrid(Config);
Then, instantiate the grid for rendering and display. Remember:Instantiated only when needed.