使用空数组初始化GridPanel和ArrayStore不起作用

时间:2010-08-22 17:05:07

标签: extjs

当我使用某些数据初始化ArrayStore时,我可以插入新记录并且所有内容都正确显示。但是,如果我使用空数组初始化ArrayStore,那么当插入的第一个记录工作时,每个后续插入都会覆盖网格中的第一个记录。 这似乎是一个简单的问题,但我找不到一种将网格初始化为空的工作方式。

那么我做错了什么?

非常感谢提前!

var myData = [
    // Initializing with the following element works.
    //['Hyannis Connector',3456.9,'Hyannis Connector Bridle Path','Hyannis Connector/Baden Powell'],
    // Initializing with this element works but leaves an empty row in the grid..
    //[]
];

// create the data store
segmentStore = new Ext.data.ArrayStore({
    fields: [
       {name: 'trailName'},
       {name: 'segmentLength', type: 'float'},
       {name: 'startJunction'},
       {name: 'endJunction'},
    ]
});

// manually load local data
segmentStore.loadData(myData);

// create the Grid
segmentGrid = new Ext.grid.GridPanel({
    region: 'south',
    store: segmentStore,
    columns: [
        {header: 'Trail Name', width: 140, sortable: true, dataIndex: 'trailName'},
        {header: 'Segment Length', width: 75, sortable: true, dataIndex: 'segmentLength'},
        {header: 'Start Junction', width: 75, sortable: true, dataIndex: 'startJunction'},
        {header: 'End Junction', width: 75, sortable: true, dataIndex: 'endJunction'},            
    ],
    stripeRows: true,
    height: 150,
    width: 600,
    title: 'Trail Segments in Route',
    layout: 'fit'      
});

var defaultData = {
            trailName: segment.getTrailName(),
            segmentLength: segment.getLength(),
            startJunction: '',
            endJunction: ''
        };
        var recId = 3; 
        var p = new segmentStore.recordType(defaultData, recId); 
        segmentStore.insert(0, p);

1 个答案:

答案 0 :(得分:-1)

答案在ExtJS论坛中提供。 我需要确保新记录的记录ID不同。