【问题标题】:EXTJS4 - get first record in a GridPanelEXTJS4 - 在 GridPanel 中获取第一条记录
【发布时间】:2011-09-25 05:25:57
【问题描述】:

我在带有 JSONstore 的 EXTJS4 中有一个 GridPanel。像这样:

var storeGridSpe = Ext.create('Ext.data.JsonStore',{            
        proxy: {
                type: 'ajax',
                url: 'get-data-for-gridspe.php',
                reader: {
                    type: 'json',
                    root: 'rows',
                    totalProperty: 'totalCount'            
                }
            },          
            autoDestroy: true,
            fields: [
                 {name: 'specie'},
                 {name: 'conta'}
            ]
        });       

var GridSpe = Ext.create('Ext.grid.GridPanel',{
            store: storeGridSpe,
            id: 'gridspe',
            flex:1,
            autoScroll: true,
            columns: [         
                {id:'specie', header: "Specie", dataIndex: 'specie', flex:1},
                {id:'conta', header: "Selezioni", dataIndex: 'conta', width:75}
            ]       
        });  

如何获取第一个 GridPanel 记录的值?例如列“specie”。

非常感谢。

【问题讨论】:

    标签: record extjs4 gridpanel


    【解决方案1】:

    根据您加载内容的方式,您可能需要等到网格存储的代理完成加载数据,例如

    storeGridSpe.on('load',reactorFunction);
    

    【讨论】:

      【解决方案2】:

      这应该有效: storeGridSpe.first().get('specie')

      ExtJS4 对模型查询进行了一些更改,因此您可能需要进行一些调整才能使其正常工作。

      这里是Ext.data.Store,它指向first() 方法,这里是Ext.data.Model,它表明get() 是要使用的方法。

      4.0.x 仍然非常不稳定,所以没有任何东西或一切都可能起作用。 :P

      【讨论】:

      • 现在它可以工作了...但是如果我尝试在另一个 js 文件中使用该函数,如下所示: var GridSpe=Ext.getCmp('gridspe'); console.log(GridSpe.getStore().first().get('specie'));我看到这个错误: GridSpe.getStore().first() is undefined 为什么?非常感谢!
      猜你喜欢
      • 2015-05-18
      • 2019-12-28
      • 1970-01-01
      • 2014-11-08
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      相关资源
      最近更新 更多