ExtJS教程

Ext.js 方法

以下是一些在 Ext JS 中大量使用的内置函数。

Ext.is 类

该类检查您使用的平台,无论是手机还是台式机、Mac 还是 Windows 操作系统。以下是与 Ext.is 类相关的方法。
方法和说明
Ext.is.Platforms
此函数返回此版本可用的平台。
例如,当您运行以下函数,它返回这样的东西-
[Object { property = "platform", regex = RegExp, identity = "iPhone"}, 
Object { property = "platform", regex = RegExp, identity = "iPod"}, 
Object { property = "userAgent", regex = RegExp, identity = "iPad"}, 
Object { property = "userAgent", regex = RegExp, identity = "Blackberry"}, 
Object { property = "userAgent", regex = RegExp, identity = "Android"}, 
Object { property = "platform", regex = RegExp, identity = "Mac"}, 
Object { property = "platform", regex = RegExp, identity = "Windows"}, 
Object { property = "platform", regex = RegExp, identity = "Linux"}]
Ext.is.Android
此函数返回true,如果你使用的是Android操作系统,否则返回false。
Ext.is.Desktop
此函数将返回 true,如果您使用桌面应用程序,否则返回 false。
Ext.is.Phone
这个函数返回true,如果你使用的是手机,否则返回false。
Ext.is.iPhone
如果您使用的是 iPhone,此函数将返回 true,否则返回 false。
Ext.is.iPod
这个函数返回true,如果你使用的是iPod,否则返回false。
Ext.is.iPad
此函数将返回true,如果您使用的是 iPad,否则返回假。
Ext.is.Windows
此函数返回true,如果你使用的是Windows操作系统,否则返回false。
Ext.is.Linux
这个函数返回true,如果你使用的是Linux操作系统,否则返回false。
Ext.is.Blackberry
此函数将返回 true,如果您使用的是 Blackberry,否则返回 false。
Ext.is.Mac
此函数返回true,如果你使用的是Mac操作系统,否则返回false。

Ext.supports 类

顾名思义,该类提供浏览器/设备当前环境是否支持该功能的信息。
方法和说明
Ext.supports.History
它检查设备是否支持 HTML 5 历史作为 window.history。如果设备支持历史记录,则返回 true,否则返回 false。
Ext.supports.GeoLocation
它检查设备是否支持地理定位方法。它在内部检查 navigator.geolocation 方法。
Ext.supports.Svg
它检查设备是否支持 HTML 5 特征可缩放矢量图形 (svg) 方法。它在内部检查 doc.createElementNS && !!doc.createElementNS("http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect。
Ext.supports.Canvas
它检查设备是否支持 HTML 5 功能画布绘制方法。它在内部检查 doc.createElement('canvas').getContext 并根据此方法的输出返回一个值。
Ext.supports.Range
检查浏览器是否支持 document.createRange 方法。

Ext.String 类

Ext.String 类有多种处理字符串数据的方法。最常用的方法是编码解码、修剪、切换、urlAppend 等。
Encoding Decoding function-这些是 Ext.String 类中可用于编码和解码 HTML 值的函数。
方法和说明
Ext.String.htmlEncode
此函数用于对 html 值进行编码以使其可解析。
示例-
Ext.String.htmlEncode("< p > Hello World < /p >"); 
Output-"&lt; p &gt; Hello World &lt; /p &gt;".
Ext.String.htmlDecode
该函数用于对编码后的html值进行解码。
示例
Ext.String.htmlDecode("&lt; p &gt; Hello World &lt; /p &gt;");
Output- "< p > Hello World < /p >"
Ext.String.trim
此功能是对字符串中不需要的空格进行修剪。
Ext.String.trim('      hello      ');
Output – "hello"
Ext.String.urlAppend
此方法用于在 URL 字符串中附加一个值。
示例-
Ext.String.urlAppend('https://www.google.com' , 'hello'); 
Output-"https://www.google.com?hello" 
Ext.String.urlAppend('https://www.google.com?index=1' , 'hello'); 
Output – "https://www.google.com?index=1&hello" 
Ext.String.toggle
该函数用于在两个不同的值之间切换值。
示例-
var toggleString = 'ASC' 
toggleString = Ext.String.toggle(a, 'ASC', 'DESC');
Output – DESC as toggleString had value ASC. Now again, if we 
print the same we will get toggleString = “ASC” this time, as 
it had value 'DESC'. 
It is similar to ternary operator 
toggleString = ((toggleString =='ASC')? 'DESC' : 'ASC' );

其他方法

方法和说明
Ext.userAgent()
此函数提供有关浏览器 userAgent 的信息。 UserAgent 用于向 Web 服务器识别浏览器和操作系统。
示例-如果您在 Mozilla 中工作,它会返回类似以下内容:"mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0"
版本相关函数
该函数返回当前使用的浏览器版本,如果该函数被调用与IE相关。在 Firefox 浏览器中,它返回 0。这些函数是 Ext.firefoxVersion、Ext.ieVersion 等。
示例-如果您使用 Firefox 浏览器并调用方法 Ext。 ieVersion 用于获取IE的版本,则返回0。如果您在IE浏览器中使用相同的方法,那么它将返回您使用的版本,例如8、9等。
Ext.getVersion()
此函数返回当前使用的 Ext JS 版本。
示例 − 如果调用 Ext.getVersion(),它返回一个数组,如版本、短版本等。
Ext.getVersion().version 返回当前使用的 Ext JS 版本。程序,如"4.2.2"。
浏览器相关函数
这些函数根据使用的浏览器返回布尔值。这些方法是 Ext.isIE、Ext.isIE6、Ext.isFF06 和 Ext.isChrome。
Example-如果您使用的是 Chrome 浏览器,则 Ext.isChrome 函数将全部返回true,否则返回假。
Ext.typeOf()
此函数返回变量的数据类型。
示例-
var a = 5;   
var b  = 'hello'; 
Ext.typeOf(a); 
Output – Number 
Ext.typeOf(b);
Output-String
DataType 相关方法-这些函数根据变量的数据类型返回布尔值
示例-
var a = ['a', 'bc'];
var b = 'hello';
var c = 123;
var emptyVariable;
var definedVariable;
function extraFunction(){return true;}
Ext.isArray(a); //返回true
Ext.isString(b); //返回true
Ext.isNumber(c); //返回true
Ext.isEmpty(emptyVariable); //返回true
Ext.isEmpty(b); //返回假
Ext.isDefined(definedVariable); //返回true
Ext.isfunction(extraFunction); //返回true
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4