Home >Web Front-end >JS Tutorial >Commonly used Extjs tools: How to use Extjs.util.Format_extjs

Commonly used Extjs tools: How to use Extjs.util.Format_extjs

WBOY
WBOYOriginal
2016-05-16 17:55:031347browse

Copy some common tools for easy search
----------String
Ext.util.Format.capitalize(string str);//Change the first letter to uppercase
Ext.util. Format.ellipsis(string value, Number length); //Intercept the specified length characters, and an ellipsis '...' will be added at the end automatically
Ext.util.Format.htmlEncode(string value); //Encode the text
lowercase(string value);//Change to lower case
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]); Such as: Ext.util.Format.date(new Date(), 'Y-m-d')=>2012-03-19
Ext.util.Format.dateRenderer(string format);//Exclusively for Ext.grid. Used by Gridpanel,

---------dormitory judgment in ColumnModel
defaultValue(Mixed value, string defalutValue);//If the first parameter is empty, return the second one, on the contrary.
undef(Mixed value;//If value is equal to empty, return an empty string, otherwise return value

==========Extended Function
1. createCallback() A callback function for the current function will be created, such as:

Copy code The code is as follows:

var sayHi = function(name){
alert('Hi' name);
}
new Ext.Button({
text: 'say hi',
handler: sayHi.createCallback(' jinshan')
});

The function of createCallback is to set default parameters for the original parameters. In the above example, 'jinshan' has been set to the corresponding one when using createCallback. Callback function, click the button and pass the parameters to sayHi().

2. createDelegate() will create a proxy function of the current function, such as:

Copy code The code is as follows:
var sayHi = function(name){
alert(name - this.text); //this .text represents the text value of the 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 be automatically converted. Go to other objects.


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

Copy code 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);//Popup 2

The interceptor will be executed before the original function is executed, and the original function will only be executed when the interceptor returns true.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn