【问题标题】:ExtJs: Store populated by Grid comes up as blankExtJs:由 Grid 填充的存储显示为空白
【发布时间】:2013-05-08 20:25:48
【问题描述】:

我正在使用 ArrayStore 并通过添加模型记录来填充它。 此存储与数据网格相关联。

现在 arraystore 对象被完美地填充,但数据没有出现在网格中。其实在调试的时候发现grid的store(datagrid.store)也有数据,但是还是没有显示在屏幕上!!

以下是我的代码。

型号:

Ext.define('Ext.ux.window.visualsqlquerybuilder.SQLAttributeValueModel', {
extend: 'Ext.data.Model',
fields: [
    {
        name: 'attribute',
        type: 'string'
    },
    {   name: 'attributeValue',
        type: 'string'
    }
  ]
});

商店:

var attrValueStore = Ext.create('Ext.data.ArrayStore', {
    autoSync: true,
    model: 'Ext.ux.window.visualsqlquerybuilder.SQLAttributeValueModel'
});

网格

Ext.define('Ext.ux.window.visualsqlquerybuilder.SQLAttributeValueGrid', {
//requires: ['Ext.ux.CheckColumn'],
autoRender: true,
extend: 'Ext.grid.Panel',
alias: ['widget.attributevaluegrid'],
id: 'SQLAttributeValueGrid',
store: attrValueStore,
columnLines: true,
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 1
})],
columns: [        
    {                        /*Expression */
        xtype: 'gridcolumn',
        text: 'Attribute',
        sortable: false,
        menuDisabled: true,
        flex: 0.225,
        dataIndex: 'attribute'
    },
    {                           /*Attribute Values*/
        xtype: 'gridcolumn',
        editor: 'textfield',
        text: 'Values',
        flex: 0.225,
        dataIndex: 'attributeValue'
    }
],
initComponent: function () {
    this.callParent(arguments);
}
});

显示网格的模式窗口

var attributeValueForm = Ext.create('Ext.window.Window', {
title:'Missing Attribute Values',
id: 'attributeValueForm',
height:500,
width:400,
modal:true,
renderTo: Ext.getBody(),
closeAction: 'hide',
items:[
    {
        xtype: 'attributevaluegrid',
        border: false,
        //height: 80,
        region: 'center',
        split: true
    }
],
buttons: [
    {
        id: 'OKBtn',
        itemId: 'OKBtn',
        text: 'OK',
        handler: function () {
            Ext.getCmp('attributeValueForm').close();
        }
    },
    {
        text: 'Cancel',
        handler: function () {
            Ext.getCmp('attributeValueForm').close();
        }
    }
]
});

现在在显示模态窗口时,我检查了存储对象的值以及网格对象内部的存储。两者都有正确的数据。

但是当窗口打开时,我得到一个空白网格

【问题讨论】:

  • 您永远不会在任何地方加载商店。你不给它分配代理或给它内联数据。商店是空的。
  • @EvanTrimboli:我理解你的意思,但实际上我错过了添加将数据添加到商店的代码。我在另一种方法中单独执行此操作,其中我创建一个模型对象,为其属性设置值并将其添加到存储中。所以商店有数据。

标签: extjs extjs4 extjs-stores


【解决方案1】:

也许您需要加载商店数据...尝试:

var attrValueStore = Ext.create('Ext.data.ArrayStore', {
    autoSync: true,
    autoLoad : true,
    model: 'Ext.ux.window.visualsqlquerybuilder.SQLAttributeValueModel'
});

【讨论】:

  • 从这里开始,有时可能需要动态加载网格,因为有时当存储准备好时(这是发生自动加载时),我们可能没有可用于存储的相关参数。要从应用程序中的任何位置加载商店,您可以使用Ext.StoreMgr.lookup('<store_itemid>').load(),其中尖括号中的值是商店的 itemid。希望这对巴兹有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 2021-01-19
相关资源
最近更新 更多