Ext JS - 如何从视图中将参数传递给控制器​​中存在的侦听器

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

我有一个观点 - 一个面板基本上...... 我里面有菜单按钮.....一个按钮内有 4 个菜单...我想每次都调用控制器中存在的一个特定功能,但参数不同...这怎么可能?

xtype: 'button',
menu: {
  items: [{
    text : 'menu 1',
    listeners: {
       click: 'controllerfunction' //with argument 1
    }
  }, {
   text : 'menu 2',
    listeners: {
       click: 'controllerfunction' // with argument 2
    }
  }]
}

我使用以下:

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

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

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

onClickViewBtn: function(btn) {
    var centerContainer = this.getCenterContainer(),
        item = centerContainer.down(btn.xtypeToOpen); // Here I use the argument.
    ...
}

亚历山大的方法可行,但还有另一种方法与您使用的风格更相似。

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') {

    }
}

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