ExtjS learning -------- Ext. define definition class, extjsext. define
Ext Class configuration items :( Note: Extjs of the Chinese version help documentation: http://download.csdn.net/detail/z1137730824/7748893
ExtJS configuration file and example: http://download.csdn.net/detail/z1137730824/7754771)
Syntax:
Define (String className, Object data, Function createdFn)
Instance:
Ext. onReady (function () {// Syntax: define (String className, Object data, Function createdFn) Ext. define ('person ', {// configuration information for the class // config attribute: configure the attribute content of the current class, And the get and set Methods config: {name: 'zhang san', age: 30}, // method defined by myself, myMethod: function () {alert ('This is your own method ');}, // Add constructor to the currently defined class: function (config) {var me = this; // obtain the current class // you can view the content in the configuration item // for (var attr in config) // {// alert (attr + ": "+ config [attr]); //} me. initConfig (config); // initialize the passed parameters}); // Ext recommended method for instantiating objects: Ext. createvar p = Ext. create ('person ', {// Class name Defined by myself: 'instantiate name', // configuration item age: 100}); alert ('name: '+ p. getName () + '-- age:' + p. getAge (); // call the default get Method p. myMethod (); // call your own defined method });Running result;
What is Extdefine of EXT?
In C language preprocessing, only identifiers are allowed without strings.
AFX_EXT_API is only an identifier and can be left unspecified. This identifier can be used to control the process of a program. If no identifier XXX is defined, the identifier XXX is defined.
Conditional compilation allows you to compile only program segments that meet the conditions in the source program, so that the generated target program is shorter, thus reducing the memory overhead and improving the program efficiency.
The pre-processing function facilitates program modification, reading, porting and debugging, and also facilitates modular program design.
The following is an example:
When writing Conditional compilation statements, we generally write:
# Ifndef _ FLAG
# Define _ FLAG constant
# Endif
However, in the source code of many programs, only identifiers are defined and no constant (value) is defined )! As in the previous program
# Ifndef _ FLAG
# Define _ FLAG
How does extjs customize functions?
To:
Ext JS user-defined functions, a broken syntax ~
I haven't understood a section in the project, and it seems that it is about Ext JS's custom functions:
Ext. ux. MessageBox = function (){
Var msgCt;
Function createBox (t, s, data, I ){
............
}
Return {
............
};
}();
After the function (createBox), there is no comma or semicolon, and a return... is directly provided ....... I suddenly fainted. No corresponding syntax is introduced in the two books available at hand. Today, I accidentally saw an article by someone else. There is another pair of parentheses behind the braces. I still haven't understood this part. I will study it later ~ Reprinted as follows for reference:
EXTJS user-defined functions. You can create a function using the following statement:
Ext. Login = function (){
Function IsLogin (){
......
}
Return {
Init: function (){
IsLogin ();
},
Login: function (){
......
}
}
At the beginning, I was quite frustrated by the function calling mechanism in JS. In the above Code, a function called Ext will be created. the Login () object should be equivalent to the meaning of a class, and other related methods can be written in it.
In return, the public method is used. The method can be called by external programs (for example, used in HTML files). Code other than return is its private method and can only be used in Ext. called in the Login () object
If you need to call the Login () method on other pages, you can directly write
<Input id = "login" onclick = "Ext. Login (). Login ()"/>
If you need to call it when loading a page, you can simply use the method in EXTJS to implement it:
Ext. onReady (Ext. Login. init, Ext. Login );
The function name here does not need to be enclosed in parentheses. The first parameter is the method to be called, and the second parameter is the scope. Generally, this object name is used.