EXTJS如何获取没有声明id的组件?

时间:2014-02-10 11:20:28

标签: extjs

 Ext.define('MyApp.view.MyVehicleGridPanel', {
   extend: 'Ext.grid.Panel',
   alias: 'widget.mygrid',
   header: false,
   store: UserStore,
   multiSelect: false,
   columns: [
                {
                    xtype: 'gridcolumn',
                    dataIndex: '_id',

                    text: 'Vehicle ID'
                },
                {
                    xtype: 'gridcolumn',
                    width: 126,
                    dataIndex: 'Plat_No',
                    text: 'Plat Number'
                },
                {
                    xtype: 'gridcolumn',
                    width: 200,
                    dataIndex: 'Name',
                    text: 'Added By'
                }
            ]
})

我在网格面板中没有任何id声明,因为它将动态使用,
所以,我使用别名来找到我的网格组件,如下面的代码

var grid = Ext.ComponentQuery.query('mygrid');
        console.log( Ext.ComponentQuery.query('mygrid') );
        if (grid.getSelectionModel().hasSelection()) { //error at here 
           var row = grid.getSelectionModel().getSelection()[0];
           console.log(row.get('Plat_No'));
        };      

但是,TypeError: grid.getSelectionModel is not a function

的firebug返回错误

找到我的网格面板组件的其他任何方式?

1 个答案:

答案 0 :(得分:9)

Ext.ComponentQuery.query()从传递的根对象中返回匹配组件的数组

因此,如果您的应用程序中只有一个mygrid组件,则可以像这样获取网格:

var grid = Ext.ComponentQuery.query('mygrid')[0];