Ext中的get、getDom、getCmp、getBody、getDoc的區別
轉自: http://wayfoon.iteye.com/blog/225862
get方法中只有一個參數,這個參數是混合參數,可以是DOM節點的id、也可以是一個Element、或者是一個DOM節點對象等。看下面的示例代碼:
Ext.onReady(function(){
var e=new Ext.Element("hello");
alert(Ext.get("hello"));
alert(Ext.get(document.getElementById("hello")));
alert(Ext.get(e));
});
Html頁面中包含一個id爲hello的div,代碼如下:
<div id="hello">aaa</div>
Ext.get("hello")、Ext.get(document.getElementById("hello"))、Ext.get(e)等三個方法都可以得到一個與DOM節點hello對應的Ext元素。
Ext.onReady(function(){
var h=new Ext.Panel({
id:"h2",
title:" ",
renderTo:"hello",
width:300,
height:200});
Ext.getCmp("h2").setTitle("新的標題");
});
在代碼中,我們使用Ext.getCmp("h2").來得到id爲h2的組件,並調用其setTitle方法來設置該面板的標題。Ext.onReady(function(){
var e=new Ext.Element("hello");
Ext.getDom("hello");
Ext.getDom(e);
Ext.getDom(e.dom);
});
Html:
<div id="hello">tttt</div>
Ext.onReady(function(){
var h=new Ext.Panel({title:"測試",width:300,height:200});
h.render(Ext.getBody());
});