首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在用Ext.define()扩展网格面板时添加行双击事件监听器?

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

Stack Overflow用户
提问于 2011-04-22 10:03:57
回答 3查看 46.9K关注 0票数 19

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

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

代码语言:javascript
复制
Ext.define('Application.usersGrid', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.usersgrid',


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

这里出了什么问题?

如果有人需要答案--这是正确的方式:

代码语言:javascript
复制
Ext.define('Application.usersGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.usersgrid',


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

http://dev.sencha.com/new/ext-js/4-0/api/Ext.grid.GridView#event-itemdblclick

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-22 14:48:08

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

代码语言:javascript
复制
listeners : {
    itemdblclick: function(dv, record, item, index, e) {
        alert('working');
    }
},

另一件事是,您似乎在extend属性中使用了Ext.grid.GridPanel。但在文档中,它是Ext.grid.Panel。但即使有了gridpanel,一切似乎都运行得很好。

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

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

票数 26
EN

Stack Overflow用户

发布于 2011-05-11 23:39:49

对于ExtJS 4中的MVC方法,还有另一种聪明的方式来定义这样的处理程序。一些示例代码:

代码语言:javascript
复制
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();
  }
});
票数 2
EN

Stack Overflow用户

发布于 2017-06-21 23:27:32

代码语言:javascript
复制
listeners: {
        select: 'xxxx',

        itemdblclick: function (dv, record, item, index, e) {
            var myBtn = Ext.getCmp('btnEdit');
            myBtn.onClick();
        }
    },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5751616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档