PDA

View Full Version : [CLOSED] Enumerating TabPanel instances on the page



vadym.f
Aug 06, 2013, 9:38 PM
Hi,

I'm trying to port a segment of code that enumerates TabPanel instances on the page. It's been working well in 1.x and I'd like it to do the same in 2.x. However, the instances of TabPanel are never found. I do realize that the namespaces have changed in 2.x so Ext.TabPanel has become Ext.tab.Panel but this makes no difference. Please advise if more info is required here.



var tabPanels = [];

callingWindow.Ext.ComponentMgr.all.each(function (c) {
if (c instanceof callingWindow.Ext.tab.Panel) {
tabPanels.push(c);
}
});

Vladimir
Aug 06, 2013, 9:56 PM
Try to use isXType method


if (c.isXType("tabpanel")) {

vadym.f
Aug 06, 2013, 9:59 PM
Thanks for your response Vladimir! I've modified the code segment as below but it never evaluates to "true" or even to not "undefined". c variable is always of String type in this setup unlike in 1.x where it's of actual component type.



var tabPanels = [];

callWnd.Ext.ComponentMgr.all.each(function (c) {
if (c.isXType && c.isXType("tabpanel")) {
tabPanels.push(c);
}
});

Vladimir
Aug 06, 2013, 10:08 PM
Try this


var tabPanels = [],
all = callWnd.Ext.ComponentMgr.all;

all.each(function (id) {
var cmp = all.get(id);
if (cmp.isXType("tabpanel")) {
tabPanels.push(cmp);
}
});

vadym.f
Aug 06, 2013, 10:13 PM
Greatly appreciated, it works! I've also tried the following workaround that does the same. I don't know which one is more efficient; probably, the each enumerator is better optimized to work with many controls on the page. Would be interested in your take.



var allControls = callWnd.Ext.ComponentMgr.all.getValues();
for (var i = 0; i < allControls.length; i++ ) {
if (allControls[i].isXType && allControls[i].isXType("tabpanel")) {
tabPanels.push(allControls[i]);
}
}

Daniil
Aug 07, 2013, 4:53 AM
In a common case, the "for" loop is more efficient than "each". A function is called for each an item in the "each" case.

You can see

Use for (...) rather than Ext.Array.each
here:
http://www.sencha.com/blog/ext-js-4-1-performance/

vadym.f
Aug 07, 2013, 12:45 PM
Thanks for the insight Daniil!