PDA

View Full Version : Best way to get index of an element in a Container



29er
11 Jan 2011, 11:12 AM
Hi,
sorry a newbie 'best practices' question.

Inside my Container i have multiple components.
When a user clicks on one of these components i want to know the index of that item within the container.
What is the best way to get this ?

Thanks

11 Jan 2011, 1:21 PM
myContainer.items.indexOf(myChildContianerRef);

29er
11 Jan 2011, 1:25 PM
thanks so much !
hey i just bought your book, reading it now. LOVE it :)

11 Jan 2011, 1:32 PM
:) thank you

wholladay
15 Jun 2012, 8:53 AM
How do I get a container object from a child element? Following is what I'm trying to do, but tr.items returns undefined.


handleHeaderKeyPress: function(event) {
if (event.keyCode == event.ENTER) {
var td = Ext.get(event.target).parent('td');
if (td) {
var tr = td.parent('tr');
if (tr) {
var index = tr.items.indexOf(td);
if (index > 0) {
this.fireEvent('headerclick', this, index, null);
return false;
}
}
}
}
return true;
},

sword-it
25 Jun 2012, 1:08 AM
Hi

I guess td and tr is dom element so you can try instead of tr.items


tr.ChildNodes

Regards