Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在使用Ext.define()扩展网格面板时添加行双击事件侦听器?_Javascript_Extjs_Gridpanel_Extjs4 - Fatal编程技术网

Javascript 如何在使用Ext.define()扩展网格面板时添加行双击事件侦听器?

Javascript 如何在使用Ext.define()扩展网格面板时添加行双击事件侦听器?,javascript,extjs,gridpanel,extjs4,Javascript,Extjs,Gridpanel,Extjs4,我正在使用Ext.define()扩展GridPanel(Ext v4) 我需要在双击网格行时获取行数据。此时,我甚至无法让事件侦听器工作: Ext.define('Application.usersGrid', { extend: 'Ext.grid.GridPanel', alias: 'widget.usersgrid', viewConfig: { listeners: { dblclick: function(dataview, index, item, e

我正在使用Ext.define()扩展GridPanel(Ext v4)

我需要在双击网格行时获取行数据。此时,我甚至无法让事件侦听器工作:

Ext.define('Application.usersGrid', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.usersgrid',


viewConfig: {
    listeners: {
        dblclick: function(dataview, index, item, e) {
            alert('dblclick');
        }
    }
},
...
这里怎么了

如果有人需要答案,这是正确的方法:

Ext.define('Application.usersGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.usersgrid',


viewConfig: {
    listeners: {
        itemdblclick: function(dataview, record, item, index, e) {
            alert('itemdblclick');
        }
    }
},
...

您不需要将侦听器放在viewconfig中。以下是我的工作配置:

listeners : {
    itemdblclick: function(dv, record, item, index, e) {
        alert('working');
    }
},
另一件事是,您似乎在extend属性中使用了
Ext.grid.GridPanel
。但在文档中它是
Ext.grid.Panel
。但即使使用gridpanel,一切似乎都很好

我建议使用ExtJS4术语,因为它可能会在以后的其他4.x版本中导致应用程序中断


现在,如果您正在使用新的MVC体系结构,您将希望将这些操作移动到控制器而不是视图。有关详细信息,请参阅MVC体系结构指南。

使用ExtJS 4中的MVC方法,还有另一种定义此类处理程序的智能方法。一些示例代码:

Ext.define('App.controller.Documents', {

  extend: 'Ext.app.Controller',
  stores: ['Documents'],
  models: ['Document'],
  views: [
    'document.List',
    'document.Edit',
    'document.Preview'
  ],  

  init: function() {

    this.control({

      /*  
       * a cool way to select stuff in ExtJS 4
       */
      'documentlist': {
        itemdblclick: this.editDocument
      },  

      /*  
       * simple access to components
       */
      'documentedit button[action=save]': {
        click: this.updateDocument
      },  

    }); 

  },  

  editDocument: function(grid, record) {
    var view = Ext.widget('documentedit');
    view.down('form').loadRecord(record);
  },  

  updateDocument: function(button) {
    var win = button.up('window'),  // new selection API
        form   = win.down('form'),  // in ExtJS 4
        record = form.getRecord(),
        values = form.getValues();

    record.set(values);
    win.close();
  }
});

如果侦听器应该是GridPanel或SelectonModel的一部分,请将其隐藏在ViewConfig中,我将遵循以下帖子:感谢您提供的提示-我也可以这样做。将我的代码更改为excated grid.Panel。我在下面的示例中使用了viewConfig。。也许我错过了什么?@Petrunov,你没有错过什么。。我认为hutten.org的作者犯了一个错误,“在ExtJS4.0中,您需要通过“viewConfig”监听GridPanel视图中的事件。。。这是错误的..顺便说一句,我自己尝试直接将侦听器添加到面板中,但没有成功-可能是因为我尝试了“dblclick”和“rowdblclick”之类的事件-我自己找不到“itemdblclick”:/@Edo。。我想你是误会了。您在哪里读到“在ExtJS4.0中,您需要通过viewConfig监听GridPanel视图上的事件”?看看文档中的视图和面板事件。@Petrunov,是的。。这可能是它不适合你的原因。在viewconfig中使用itemdbclick尝试您的代码,并让我们知道结果…使用这种方法,您如何处理覆盖侦听器?我的意思是,如果你在线程上遇到一些问题,怎么样?欢迎这么做,如果没有解释,发布一个代码作为答案可能不是很有用。你能把你的答案修改一下,让我解释一下吗?你可能会有兴趣阅读并参加考试。
listeners: {
        select: 'xxxx',

        itemdblclick: function (dv, record, item, index, e) {
            var myBtn = Ext.getCmp('btnEdit');
            myBtn.onClick();
        }
    },