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.