【问题标题】:can't load json data into a grid extjs无法将 json 数据加载到网格 extjs 中
【发布时间】:2013-09-21 13:36:38
【问题描述】:

我尝试了我找到的每一个答案(在 Stackoverflow 中有很多)来解决我的 extjs 存储问题,但即使网格正确显示,数据仍然没有显示在网格中。我很困惑,所以我正在写我能够在这个网站上阅读答案的“商店”。我不知道为什么它没有将数据加载到网格中。如果您需要更多信息来帮助,请询问。

store: Ext.create('Ext.data.Store', {
    autoLoad: true,
    storeId: 'StoreName',
    fields: ['id','name'],
    data : JsonObject,
    model: 'ModelName',
    proxy: {
        type: 'memory',
        reader: {
        type: 'json',
        record: 'JsonRoot'
    }
}

})

通过 ajax 调用将网格加载到新窗口中。新窗口的代码如下:

Ext.create('Ext.window.Window', {
                    title: 'GridTitle',
                    height: 200,
        width: 400,
        layout: 'fit',
        items: {  
        xtype: 'grid',
                    border: false,
        columns: [
                    {
            text     : 'id',
                            flex     : 1,
            sortable : true,
            dataIndex: 'id'
        },
        {
                text     : 'name',
            width    : 300,
            sortable : true,
            dataIndex: 'name'
        }],

我确实觉得 ext.js 不读取带有列的部分,因为它没有索引我在 json 中传递给它的数据的名称和 ID。

【问题讨论】:

  • 您以 Json 的形式带来数据。为什么不尝试使用 -type:"ajax" 并为商店提供 URL
  • 导致网格已经进入 Ajax 调用,并且 json 是该调用的响应文本。所以我不需要进行其他调用来获得 json,它已经存在,并且可以用作“内存”。它不会引发任何异常,所以我认为它是正确的。

标签: javascript json grid extjs4 store


【解决方案1】:

解决方案是如此简单,以至于我都不好意思说出来。

reader: {
         type: 'json',
     root: 'jsonRoot'
        }

代替:

reader: {
         type: 'json',
     record: 'jsonRoot'
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 2012-07-13
    • 2016-02-17
    相关资源
    最近更新 更多