Extjs学习笔记(九) 核心包core

1.Ext.core.Element 
    API解释
        他是组建和控件的基础
        他对一个DOM对象的封装(Document Object Model)
    1.1如何得到Element 
        Ext.core.Element.fly(String/HTMLElement el, [String named] ) : Element

Html代码  收藏代码
  1. <div id="div01">  
  2.     我事第一个div  
  3. </div>  

 css:

Html代码  收藏代码
  1. .divC{color:red}  

 js:

Js代码  收藏代码
  1. var div01 = Ext.core.Element.fly("div01");  
  2. //1.鼠标滑过的时候增加一个样式滑出的时候移除样式  
  3. div01.addClsOnOver("divC");  

 

Ext.get(Mixed el) : Element

API 写道
get( String/HTMLElement/Ext.Element el ) : Ext.Element

Retrieves Ext.Element objects. get is an alias for Ext.Element.get.

This method does not retrieve Components. This method retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by its ID, use Ext.ComponentManager.get.

Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with the same id via AJAX or DOM.
Parameters

el : String/HTMLElement/Ext.Element

The id of the node, a DOM Node or an existing Element.

Returns

Ext.Element

The Element object (or null if no matching element was found)

 这个方法不检索组件,检索Ext.Element封装的DOM元素。用Ext.ComponentManager.get方法,根据ID查找。并且支持简单的缓存,防止重复查找。

Js代码  收藏代码
  1. //2.得到el的方法是Ext.get()  
  2. var input01 = Ext.get("input01");  
  3. var fn1 = function(){  
  4.     alert("单击B按钮调用这个函数");  
  5. };  

 

  
    1.2    Element 相关方法 
        addClsOnClick( String className ) : Ext.core.Element
        addClsOnOver( String className ) : Ext.core.Element
        addKeyMap( Object config ) : Ext.util.KeyMap
        addKeyListener( Number/Array/Object/String key, Function fn, [Object scope] ) : Ext.util.KeyMap

Js代码  收藏代码
  1.              input01.addKeyMap({key:Ext.EventObject.B,ctrl:false,fn:fn1,stope:input01});  
  2.   
  3. nput01.addKeyListener({key:Ext.EventObject.X,ctrl:true},function(){  
  4. alert("单击ctrl+x")  
  5. ,input01);  

 

        appendChild( String/HTMLElement/Array/Element/CompositeElement el ) : Ext.core.Element

Js代码  收藏代码
  1. function createChild(){  
  2.     var el = document.createElement("h5");  
  3.     el.appendChild(document.createTextNode("我是被追加的"));  
  4.     return el;  
  5. }  
  6. Ext.get("div02").appendChild(createChild());  
  7.   
  8. Ext.getBody().createChild({  
  9.     tag:'li',  
  10.     id:'item1',  
  11.     html:'我是第一个个节点'  
  12. });  

 


        createChild( Object config, [HTMLElement insertBefore], [Boolean returnDom] ) : Ext.core.Element

Js代码  收藏代码
  1. function createChild(){  
  2.     var el = document.createElement("h5");  
  3.     el.appendChild(document.createTextNode("我是被追加的"));  
  4.     return el;  
  5. }  
  6. Ext.get("div02").appendChild(createChild());  
  7.   
  8. Ext.getBody().createChild({  
  9.     tag:'li',  
  10.     id:'item1',  
  11.     html:'我是第一个个节点'  
  12. });  

 


2.Ext.core.DomHelper 
    API解释
        他可以很容易的操作页面的HTML.和DOM元素
    append( Mixed el, Object/String o, [Boolean returnElement] ) : HTMLElement/Ext.core.Element
        追加一个孩子

Js代码  收藏代码
  1. //append( Mixed el, Object/String o, [Boolean returnElement] ) :  
  2. var p = Ext.create("Ext.panel.Panel",{  
  3.     width:400,  
  4.     height:300,  
  5.     html:"<p id='p1'>hello word</p>",  
  6.     id:'myp01',  
  7.     title:'my panel',  
  8.     renderTo:"myp"  
  9. });  
  10. Ext.core.DomHelper.append(Ext.get("p1"),"<br><div id='d'>wo sho bei zhuijia de </div>");  

 

 applyStyles( String/HTMLElement el, String/Object/Function styles )

Js代码  收藏代码
  1. Ext.core.DomHelper.applyStyles(Ext.get("p1"),"color:red");  

 

    //下面两个是被当做兄弟追加的
insertAfter( Mixed el, Object o, [Boolean returnElement] ) : 
insertBefore( Mixed el, Object/String o, [Boolean returnElement] ) :

 

createDom( Object/String o ) : HTMLElement

Creates new DOM element(s) without inserting them to the document.

Js代码  收藏代码
  1. var html = Ext.core.DomHelper.createDom("<h1>hello</h1>");  
  2. alert(html)  

 

overwrite( String/HTMLElement/Ext.Element el, Object/String o, [Boolean returnElement] ) : HTMLElement/Ext.Element

Creates new DOM element(s) and overwrites the contents of element with them.

 

3.Ext 
    //方法是执行在文件加载完之后,onload 和 image 加载之前
    onReady( Function fn, Object scope, Boolean withDomReady, Object options ) : void    
    get()//不在多说
    query( String path, [Node root] ) : Array 
        http://www.w3school.com.cn/xpath/xpath_axes.asp
        语法看 Ext.DomQuery

Js代码  收藏代码
  1. //2.通过类似XML的选测方式来查询我们的节点  
  2. var arr = Ext.query("TR TD");  
  3. //alert(arr)  

 


    getCmp( String id ) : void 
        返回组建管理器管理的ID组建
    isEmpty( Mixed value, [Boolean allowEmptyString] ) : Boolean

Js代码  收藏代码
  1.     //4.isEmpty  
  2. //  alert(Ext.isEmpty({}));  
  3. //  alert(Ext.isEmpty('',true));//flase  
  4. //  alert(Ext.isEmpty('',false));//true  


    namespace( String namespace1, String namespace2, String etc ) : Object

   创建名称空间用于局部变量和类,所以它们并不是全局的

Js代码  收藏代码
  1. //5.namespace  
  2. Ext.namespace("COM.PCAT.MODE","COM.PCAT.CORE");  
  3. COM.PCAT.MODE.A = {  
  4.     name:'uspcat'  
  5. };  
  6. COM.PCAT.CORE.A = function(){  
  7.     alert("COM.PCAT.CORE.A");  
  8. };  

    each( Array/NodeList/Mixed iterable, Function fn, Object scope, Boolean reverse ) : Boolean

   遍历

Js代码  收藏代码
  1. //6.each  
  2. var array = [-1,23,43543,4,6,7,8];  
  3. Ext.each(array,function(i){  
  4.     //alert(i)  
  5. })  

 

    apply( Object object, Object config, Object defaults ) : Object

    扩展函数

Js代码  收藏代码
  1. //7.apply  
  2. var a = {  
  3.     name:'yfc'  
  4. }  
  5. Ext.apply(a,{getName:function(){  
  6.     //this有时代表本类,有时代表调用本类的类  
  7.     alert(this.name);  
  8. }});  

 

    encode( Mixed o ) : String

   将对象编码成json字符串。对象中的方法不行。

Js代码  收藏代码
  1. //8.encode( Mixed o ) : String  
  2. //alert(Ext.encode(a));  

  

   htmlDecode( String value ) : String

  转换HTML的转译符  &nbsp ->空格

Js代码  收藏代码
  1. //9.htmlDecode  
  2. //Ext.Msg.alert("hello",Ext.htmlDecode("<h1>hel&gtlo</h1>"));  
  3. //10.select  
  4. //var o1 = Ext.select("divC");  
  5. //alert(o1)  

 

 typeOf( Mixed value ) : String

  判断对象类型

Js代码  收藏代码
  1. alert(Ext.typeOf({}));//object  
  2. alert(Ext.typeOf(""));//string  
  3. alert(Ext.typeOf(function(){}));//function  

 

    select( String/Array selector, [Boolean unique], [HTMLElement/String root] )

posted on 2013-12-01 17:19  kangxuebin  阅读(263)  评论(0)    收藏  举报

导航