将网格的记录提取到 object

Extract grid's records into an object

假设我有一个网格并且想提取它的记录。

let record = {};
grid.rowAt(rowIndex) 
    .cellAt(cellIndex)
    .focus()
    .get('innerText')
    .and(function (future) {
        record.columnName = future.data.innerText;
    });

如何计算出网格有多少列和多少行?

根据列的索引,我怎样才能得到相应 header 的名称?

以下示例应有助于演示如何使用 Sencha Test 从 Ext JS 网格中的行获取行数、列数、列标题和获取记录object:

describe('Grid', function() {
    beforeAll(function() {
        ST.grid('array-grid')
            .rowAt(0);      // Wait for data to be in the grid
    });

    it('should check the total number of rows and columns', function() {
        ST.grid('array-grid')
            .execute(function(grid) {
                var values = {
                    recordCount: grid.getStore().getCount(),    // Get the Store count (same as row count)
                    columnCount: grid.query('gridcolumn:visible').length    // Get the number of visible columns
                };

                return values;
            })
            .and(function(future) {
                var result = future.data.executeResult;

                expect(result.recordCount).toEqual(100);
                expect(result.columnCount).toEqual(6);
            });
    });

    it('should get the column title for the fifth column in the grid', function() {
        var columnTitle;

        ST.component('array-grid gridcolumn:visible:nth-child(5)')
            .get('text')
            .and(function(future) {
                // Do something with the column title
                columnTitle = future.data.text;

                expect(columnTitle).toEqual('Last Updated');
            });
    });

    it('should get the record for the third grid row and check some of its values', function() {
        ST.grid('array-grid')
            .rowAt(2)
            .getRecord()
            .and(function(future) {
                var record = future.data.record;

                expect(record.name).toEqual('Dabvine');
                expect(record.price).toEqual(29.94);
            });
    });
});