Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext JS - how to pass arguments to listener present in controller from view

I have a view - a panel basically ... i have menu buttons in it ..... 4 menus inside a button ... i want to call one particular function present in the controller each time but with different parameters ... how is it possible ?

xtype: 'button',
menu: {
  items: [{
    text : 'menu 1',
    listeners: {
       click: 'controllerfunction' //with argument 1
    }
  }, {
   text : 'menu 2',
    listeners: {
       click: 'controllerfunction' // with argument 2
    }
  }]
}
like image 438
Anindya Halder Avatar asked Dec 02 '22 15:12

Anindya Halder


2 Answers

Alexander's way works, but there is another way that is more in the same style you were using.

xtype: 'button',
menu: {
  items: [{
    text : 'menu 1',
    listeners: {
       click: {fn: 'controllerfunction', extraArg: 'yes'}}
    }
  }, {
   text : 'menu 2',
    listeners: {
       click: {fn: 'controllerfunction', extraArg: 'no'}}
    }
  }]
}

// In your controller
controllerFunction: function(event, target,options) {
    if (options.extraArg === 'yes') {

    }
}

See https://fiddle.sencha.com/#fiddle/15c7

like image 115
Juan Mendes Avatar answered May 08 '23 20:05

Juan Mendes


I use the following:

xtype: 'button',
xtypeToOpen:'listView', // This is the argument.
id: 'btnListView',
text: 'List'

and

xtype: 'button',
xtypeToOpen:'gridView', // This is the argument.
id: 'btnGridView',
text: 'Grid'

and

'button[id$=View]': {
    click: this.onClickViewBtn
},

and

onClickViewBtn: function(btn) {
    var centerContainer = this.getCenterContainer(),
        item = centerContainer.down(btn.xtypeToOpen); // Here I use the argument.
    ...
}
like image 43
Alexander Avatar answered May 08 '23 21:05

Alexander