最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 12

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./#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.
    ...
}
发布评论

评论列表(0)

  1. 暂无评论