ExtJS-点击一个按钮就可以获得一个网格的选定值



我是ExtJS的新手,所以我发现在获得这个简单的逻辑时有点困难。

我在选项卡面板中有一个网格。我在这个网格的和处添加了两个按钮"添加"one_answers"更新"。单击"添加",我想查看所选行的值。

代码如下:

Ext.define('XYZ.view.PlantInformation', {
      extend: 'Ext.panel.Panel',
      alias: 'widget.plantinformation',
      requires: [
        'XYZ.view.PlantInformationOldViewModel1',
        'Ext.tab.Panel',
        'Ext.tab.Tab',
        'Ext.grid.Panel',
        'Ext.grid.column.Column',
        'Ext.view.Table',
        'Ext.toolbar.Spacer'
      ],
      viewModel: {
        type: 'plantinformation'
      },
      height: 500,
      width: 800,
      layout: 'fit',
      title: 'Plant Information',
      defaultListenerScope: true,
      items: [{
        xtype: 'tabpanel',
        activeTab: 0,
        items: [{
            xtype: 'panel',
            scrollable: 'true',
            title: 'Plant',
            items: [{
              xtype: 'gridpanel',
              itemId: 'PlantTab',
              scrollable: true,
              bodyBorder: true,
              bind: {
                store: 'PlantStore'
              },
              columns: [{
                xtype: 'gridcolumn',
                dataIndex: 'ID_PLANT',
                text: 'Plant ID'
              }, {
                xtype: 'gridcolumn',
                dataIndex: 'DS_PLANT',
                text: 'Plant Name',
                flex: 1
              }],
              dockedItems: [{
                xtype: 'panel',
                dock: 'bottom',
                width: 100,
                layout: {
                  type: 'hbox',
                  align: 'stretch',
                  pack: 'end'
                },
                items: [{
                  xtype: 'button',
                  flex: 1,
                  text: 'Add',
                  listeners: {
                    click: 'onButtonClick'
                  }
                }, {
                  xtype: 'tbspacer',
                  flex: 1
                }, {
                  xtype: 'button',
                  flex: 1,
                  text: 'Update'
                }]
              }],
              listeners: {
                select: 'onGridpanelSelect'
              }
            }]
          },
        ],
        onButtonClick: function(button, e, eOpts) {
          var grid = Ext.getCmp('PlantTab');
          var selection = grid.getSelectionModel().getSelection()[0];
          alert(selection);
        },
        onGridpanelSelect: function(rowmodel, record, index, eOpts) {

        }
      });

我收到一个错误:

未捕获类型错误:无法读取未定义的属性"getSelectionModel">

这件简单的事我做错了什么?

提前!

如果您想用Ext.getCmp检索组件,请替换:

itemId: 'PlantTab'

带有:

id: 'PlantTab'

在您的网格配置中。

id是全局的,itemId的作用域在父容器内。

最新更新