Ext JS 控制項查詢方法

2021-08-07 14:19:55 字數 1454 閱讀 5941

ext js提供了單例類ext.componentquery 用於在頁面中搜尋元件,其語法和css選擇器非常相似。主要是使用ext.componentquery.query() 這個方法來查詢,其返回值是陣列:ext.component,看乙個例子:

ext.onready(function

() ,

items: [, , , ]}]}

]});

var datefields = ext.componentquery.query('datefield');

console.log(datefields);//這是乙個陣列!

console.log(datefields[0].fieldlabel);//輸出:date of birth

var datefieldsinpanels = ext.componentquery.query('panel > datefield');

console.log(datefieldsinpanels[0].fieldlabel);//輸出:date of birth

var emailinmycontainer = ext.componentquery.query('#mycontainer #email');

console.log(eemailinmycontainer[0].fieldlabel);//輸出:email

});

元件可以通過下表的方式檢索:

查詢型別

例子(上面的案例)

xtype

ext.componentquery.query(『datefield』)

結果:編號3

itemid 或 id

ext.componentquery.query(『#email』)(id前需要加上#符號)

結果:編號4

attributes

ext.componentquery.query(『textfield[fieldlabel=」last name」]』)

結果:編號2

descendant

ext.componentquery.query(『#mycontainer textfield』)

結果:編號1、2、3、4,因為datefield是textfield的子類,也算乙個

direct child

ext.componentquery.query(『#mycontainer > textfield』)

結果:編號1、2,因為編號3、4是孫輩,不算

parent

ext.componentquery.query(『#email ^ container』)

結果:容器a、b、c

查詢子控制項和父控制項方法

一 查詢某種型別的子控制項,並返回乙個list集合 public listgetchildobjects dependencyobject obj,type typename where t frameworkelement childlist.addrange getchildobjects ch...

extjs 查詢快取

有的時候頁面載入好了從資料庫得來的資料。當條件查詢的時候,我們可以查詢快取裡的資料,所以當 extjs的gridpanel store確定的時候 我們可以利用 store裡的filter方法或是filterby方法來過濾快取資料 filter string field,string regexp v...

ExtJs 表單與輸入控制項

簡單表單建立 var form new ext.form.formpanel defaulttype textfield labelalign right title form lablewidth 50,frame true,width 220,items fieldlabel 文字框 butto...