tags:

views:

421

answers:

2

Hi eveyrone,

I'm looking for an equivalent method to select a class element like this $(".className") in Jquery for ExtJS.

I understand that Ext.get() only takes in an id. Your help will be very much appreciated.

Cheers, Mickey

Edited:

Let me explain further. I want to be able to do something like Ext.get after I did a "select". For example:

$(".className").css("width");

I understand that Ext.Element has getWidth() method. I was hoping I can do something like...

Ext.select(".className").getWidth(); // it just return me [Object object]

Maybe i don't understand it well.

Thanks a mil.

+3  A: 

I think you are looking for:

Ext.query(".className");

This method allows you to get elements by the given query string like jQuery does.

EDIT

var els=Ext.query(".className"), ret=[];
for(i=0;i<els.length;i++)
{
    ret.push(els[i].getWidth());
}
mck89
I have edited my question. Hope you can help me out. I want to be able to access Ext.Element methods (i.e. getWidth()). However, your suggested method of Ext.query return an array.
Mickey Cheong
I see. I guess ExtJS can't be as elegant as Jquery with $(".className").css("width") to return the width. Thanks alot.
Mickey Cheong
Ext.query is more useful when using DomQuery outside of Ext (hence, it returns a plain array). If you want to operate on Element objects, use Ext.select.
bmoeskau
+3  A: 

Yes, Ext.select() is what you want. It returns a CompositeElement (same API as a single Element, but contains an internal collection of all selected elements). You could do this to see the widths of each element:

Ext.select('.className').each(function(el){
    console.log(el.getWidth());
}); 

The way you called it is more useful for operating on the elements in some way, e.g.:

Ext.select('.className').setWidth(100);
bmoeskau