0

In my application, I have several views that have the same buttons on the toolbar. In the contraoller, I would like to use one ComponentQuery only to listen to the click event on all similar buttons.

My view 1 is as follows:

alias: 'widget.view-type1',
dockedItems: [{
    xtype: 'toolbar',
    dock: 'top',
    items: [{
        text: 'Add',
        itemId: 'add'
    }

In my controller, instead of calling

init: function(){
    this.control({
        'view-type1 #add, view-type2 #add, view-type3 #add, view-type4 #add': {click: this.onButtonAdd},

I'd like something like

init: function(){
    this.control({
        'view-generic #add': {click: this.onButtonAdd},

I should be able to add a config property to my view 1, like:

secondaryAlias: 'widget.view-generic',

But this does not exist.

My question is, how to declare those views in such a way, that I can target them all together with a simple ComponentQuery. I hope this explanation is clear enough.

Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121

1 Answers1

1

Add a property for every of your classes like this:

mySecondaryAlias: 'view-generic',

And then use search by property:

Ext.ComponentQuery.query('[mySecondaryAlias=view-generic] #add')
V G
  • 18,822
  • 6
  • 51
  • 89
  • Maybe I was not clear enough. Your query will find the button on `view-type1`-view, but it will not find the same button on the three other similar views. – Lorenz Meyer Nov 18 '13 at 19:37
  • Corrected that. Also please note that `#add` is in a toolbar and you say that the query finds it, but I didn't try it. – V G Nov 18 '13 at 19:40