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
}
}]
}
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
}
}]
}
Share
Improve this question
asked Feb 9, 2016 at 15:08
Anindya HalderAnindya Halder
1192 silver badges12 bronze badges
2
- 1 stackoverflow./questions/19268977/… – RIYAJ KHAN Commented Feb 9, 2016 at 15:13
- I tries to do this way @RIYAJKHAN . Everything is in declarative way ..there is no launch function in my view...when i use scope : this inside my listener , that does not point to my controller – Anindya Halder Commented Feb 9, 2016 at 15:28
2 Answers
Reset to default 12Alexander'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./#fiddle/15c7
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.
...
}