ext.js中网格中的Itemtap监听器不起作用

时间:2017-08-03 11:13:03

标签: javascript events extjs listeners

我是ext.js中的新手,我正在试图解释为什么我借用http://docs.sencha.com/extjs/6.5.1/guides/quick_start/handling_events.html教程借用这个例子 不适合我。

我为代码添加了两个监听器:itemmouseenter - 它正常工作,itemtap - 它无效。

Ext.create('Ext.tab.Panel', {
    renderTo: Ext.getBody(),
    xtype: 'tabpanel',
    items: [{
  title: 'Employee Directory',
  xtype: 'grid',
  iconCls: 'x-fa fa-users',
  listeners: {
    itemmouseenter: function() {
      console.log( 'Mouse Enter');
    },
    itemtap: function(view, index, item, e) {
        console.log("item tap")
    }
  },
  store: {
      data: [{
          "firstName": "Jean",
          "lastName": "Grey",
          "officeLocation": "Lawrence, KS",
          "phoneNumber": "(372) 792-6728"
      }, {
          "firstName": "Phillip",
          "lastName": "Fry",
          "officeLocation": "Lawrence, KS",
          "phoneNumber": "(318) 224-8644"
      }, {
          "firstName": "Peter",
          "lastName": "Quill",
          "officeLocation": "Redwood City, CA",
          "phoneNumber": "(718) 480-8560"
      }]
  },
  columns: [{
      text: 'First Name',
      dataIndex: 'firstName',
      flex: 1
  }, {
      text: 'Last Name',
      dataIndex: 'lastName',
      flex: 1
  }, {
      text: 'Phone Number',
      dataIndex: 'phoneNumber',
      flex: 1
  }]
  }, {
     title: 'About Sencha',
     iconCls: 'x-fa fa-info-circle'
 }]
});

2 个答案:

答案 0 :(得分:0)

In classic the event is itemclick. The sample you're looking at is for modern.

答案 1 :(得分:0)

因为我已经检查过sencha小提琴 itemtap 在现代工作正常,但对于Classic,你必须使用 itemlick 。我在我的小提琴中使用相同的代码,您可以通过以下链接查看: -

EXTJS GRID ITEM TAP

Ext.application({
    name : 'Fiddle',

    launch : function() {
        var panel = Ext.create('Ext.window.Window', {
            width:'100%',
            height:'100%',
            layout:'fit',
            items:[{
                xtype: 'tabpanel',
                items: [{
                    title: 'Employee Directory',
                    xtype: 'grid',
                    layout:'fit',
                    iconCls: 'x-fa fa-users',
                    listeners: {
                        itemmouseenter: function() {
                            console.log('Mouse Enter');
                        },
                        itemclick: function(grid, record, item, index, e, eOpts) {
                            Ext.Msg.alert('Info',`You have tapped on ${index+1} item`);
                        }
                    },
                    store: {
                        data: [{
                            "firstName": "Jean",
                            "lastName": "Grey",
                            "officeLocation": "Lawrence, KS",
                            "phoneNumber": "(372) 792-6728"
                        }, {
                            "firstName": "Phillip",
                            "lastName": "Fry",
                            "officeLocation": "Lawrence, KS",
                            "phoneNumber": "(318) 224-8644"
                        }, {
                            "firstName": "Peter",
                            "lastName": "Quill",
                            "officeLocation": "Redwood City, CA",
                            "phoneNumber": "(718) 480-8560"
                        }]
                    },
                    columns: [{
                        text: 'First Name',
                        dataIndex: 'firstName',
                        flex: 1
                    }, {
                        text: 'Last Name',
                        dataIndex: 'lastName',
                        flex: 1
                    }, {
                        text: 'Phone Number',
                        dataIndex: 'phoneNumber',
                        flex: 1
                    }]
                }, {
                    title: 'About Sencha',
                    iconCls: 'x-fa fa-info-circle'
                }]
            }]
        });
        panel.show()
    }
});