Common Extjs tools: Extjs. util. Format usage _ extjs

Source: Internet
Author: User
Tags html encode
Common Extjs tools: Extjs. util. Format
---------- String
Ext. util. Format. capitalize (string str); // uppercase the first letter.
Ext. util. Format. ellipsis (string value, Number length); // truncates a specified length character. The ellipsis '...' is automatically added to the end '...'
Ext.util.Format.html Encode (string value); // Encode the text
Lowercase (string value); // small write
StripScripts (Mixed value); // Delete All Script tags
StripTags (Mixed value); // Delete All tags
Substr (value, start, length)
Trim (value)

---------- Date
Ext. util. format. date (Mixd value, [String format]); for example: Ext. util. format. date (new Date (), 'Y-m-d') => 2012-03-19
Ext. util. Format. dateRenderer (string format); // used specially for Ext. grid. Gridpanel.

--------- Dormitory judgment
DefaultValue (Mixed value, string defalutValue); // if the first parameter is null, the second parameter is returned.
Undef (Mixed value; // If value is null, null strings are returned; otherwise, value is returned.

=========== Extended Function
1. createCallback () creates the callback function of the current function, for example:

The Code is as follows:


Var sayHi = function (name ){
Alert ('Hi' + name );
}
New Ext. Button ({
Text: 'say Hi ',
Handler: sayHi. createCallback ('jinshance ')
});


CreateCallback is used to set default parameters for the original parameters. In the preceding example, when createCallback is used, 'jinshance' has been set to the corresponding callback function. click the button to pass the parameter to sayHi ().

2. createDelegate () creates the proxy function of the current function.
For example:

The Code is as follows:


Var sayHi = function (name ){
Alert (name-this. text); // this. text indicates the text value of btn function Say Hi,
}
Var btn = new Ext. Button ({
Text: 'say Hi'
});
Btn. on ('click', sayHi. createDelegate (btn, ['jisnh ']);


This creates a proxy, and sayHi points to btn .. If btn is changed to another object, sayHi will automatically go to another object.


3. createInterceptor (fun, scope); Set interceptor for the current function, similar to the AOP concept. For example:

The Code is as follows:


Var sayHi = function (name ){
Alert (name );
}
SayHi ('1 ');
Var sayHito = sayHi. createInterceptor (function (name ){
Return name = '2 ';
});
SayHito (1); // No prompt
SayHito (2); // pop up 2


The interceptor will execute the original function before the original function is executed, and it will only execute the original function when the interceptor returns true.
Related Article

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.