我正在使用 Ext.data.Store 调用一个 PHP 脚本,该脚本返回一个 JSON 响应,其中包含一些关于将在查询中使用的字段的元数据(唯一名称、表、字段和用户友好的标题)。然后我遍历每个 Ext.data.Record 对象,将我需要的数据放入一个数组 ( this_column),将该数组推到另一个数组 ( columns) 的末尾,并最终将其传递给 Ext.grid.ColumnModel 对象。
我遇到的问题是 - 无论我正在测试哪个查询(我有很多,大小和复杂性不同),列数组总是按预期工作,直到columns[15]. 在columns[16]处,从该点和之前的所有索引都用 的值填充columns[15]。这种行为一直持续到循环到达 Ext.data.Store 对象的末尾,此时整个数组包含相同的值。
这是一些代码:
columns = [];
this_column = [];
var MetaData = Ext.data.Record.create([
    {name: 'id'},
    {name: 'table'},
    {name: 'field'},
    {name: 'title'}
]);
// Query the server for metadata for the query we're about to run
metaDataStore = new Ext.data.Store({
    autoLoad: true,
    reader: new Ext.data.JsonReader({
        totalProperty: 'results',
        root: 'fields',
        id: 'id'
    }, MetaData),
    proxy: new Ext.data.HttpProxy({
        url: 'index.php/' + type + '/' + slug
    }),
    listeners: {
        'load': function () {
            metaDataStore.each(function(r) {
                this_column['id'] = r.data['id'];
                this_column['header'] = r.data['title'];
                this_column['sortable'] = true;
                this_column['dataIndex'] = r.data['table'] + '.' + r.data['field'];
                // This display valid information, through the entire process
                console.info(this_column['id'] + ' : ' + this_column['header'] + ' : ' + this_column['sortable'] + ' : ' + this_column['dataIndex']);
                columns.push(this_column);
            });
            // This goes nuts at columns[15]
            console.info(columns);
            gridColModel = new Ext.grid.ColumnModel({
                columns: columns
            });