PDA

View Full Version : How to get active tab?



AlainP
13 Sep 2007, 7:50 AM
Hi,

I am kinda new to all of this Ext thing and JS and I am having some trouble to figure out how to get the active tab from my center region from a function that is outside of the Borderlayout call. I will need to call this every time the user clic on a menu item to pass the tab id to my RoR backend controller.

Basically, I dont know what code I should put in front of this:

getRegion('center').getActiveTab.id

Any help would be great! Thanks

fay
13 Sep 2007, 8:12 AM
Pretty sure this has been covered a number of times. You really need to make use of the search facility as almost every newbie-type question has been asked and answered before.



Layout = new Ext.BorderLayout(document.body, {
// ...
});

var Tabs = Layout.getRegion('center').getTabs();

var CurrentIndex = Tabs.items.indexOf(Tabs.getActiveTab());

AlainP
13 Sep 2007, 9:43 AM
Thanks but I used the search to make sure I didnt look newbish...

The thing is that I cant access the layout variable from my function since they are in different files/functions. So the variable layout is out of the scope.

Animal
13 Sep 2007, 9:49 AM
You need a page-global object which encapsulates the requirements of all widgets on the page. It ca hold a reference to the Layout, and other central information so that all modules can reference it.

AlainP
13 Sep 2007, 10:35 AM
Thanks, I will give this a try then.

I was hoping for a solution that would have been more elegant, global variables always end up creating a mess :-S

brian.moeskau
13 Sep 2007, 11:11 AM
Not a global variable in the traditional sense -- an object that has visibility into all of your other components that need to talk. Commonly people create an application class singleton, which is an example of what Animal is talking about, and build the widgets and other components within its scope so that the application components will be able to communicate. The FeedViewer3 example coming out with 2.0 is a decent example of how to structure things.