Xtype Definition)

Source: Internet
Author: User
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);

WhereXtypeYesMygridThe general form of the class name isExt. UX. mygrid. The preceding statementRegisteredNewXtypeIn other words,XtypeMygridAnd classExt. UX. mygridIs 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. mygridClass 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 instantiateXtypeMygridObject, 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.