Take the 2-minute tour ×

Okay so here's the story:

I have two buttons with two different controllers(handlers) - A plus and a minus button:

[ + ] addBtn        [ - ] subtractBtn - hidden

The first time you click the addBtn, the subtractBtn should show.

The max amount of clicks for either button is 2.

When you click the addBtn, the count of clicks should increment by 1.

When you click the subtractBtn, the count of clicks should decrement by 1.

When the count reaches 0, the subtractBtn should disappear

The issue here is I need to somehow store this variable(count) into a variable that both controllers can read.

If anyone can answer how this could be done in Ext JS, that would be muy excellente and I will provide tons of upvotes. Thank you!

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Use count as a global variable and here is a working example: http://jsfiddle.net/x_window/HVkhy/1/

var count = 0;

var btnAdd = new Ext.Button({
    width: 50,
    text: '+',
    handler: function(){
        if(count > 0 && btnSubs.hidden)
        if(count > 1 && !btnAdd.hidden)

var btnSubs = new Ext.Button({
    width: 50,
    hidden: true,
    text: '-',
    handler: function(){
        if(count < 2 && btnAdd.hidden)
        if(count < 1 && !btnSubs.hidden)

var panel = new Ext.Panel({
    width: 200,
    items: [btnAdd, btnSubs],
    renderTo: 'content'

share|improve this answer
EDIT, This is actually perfect, thank you very much!!! –  Clay Banks Aug 8 '13 at 23:14
How could I allow different controllers to access the count variable? (i.e. different .js files) –  Clay Banks Aug 9 '13 at 1:16

I'm assuming the buttons have a common ancestor (maybe a container, or panel). You could keep the variable there. If you're using button handlers, you can access the parent container by using up()

handler: function(btn, e) {

You may need to look over http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.ComponentQuery to figure out which selector to use for the up() function.

share|improve this answer
Ahh, good idea my friend. I will try this out. –  Clay Banks Aug 8 '13 at 20:55

You can always access controller2 from a controller1 with the getController method of the application instance, which you get in the onLaunch method of controller1.

share|improve this answer
No way! Awesome Thank you so much!! –  Clay Banks Aug 9 '13 at 12:52

Your Answer


