【问题标题】:How to load data in extJS grid from JSONStore?如何从 JSONStore 加载 extJS 网格中的数据?
【发布时间】:2011-12-11 04:34:13
【问题描述】:

我在将数据从 JSON 存储加载到 EXT 网格时遇到问题。以下是代码:

var store = new Ext.data.JsonStore({
        root: 'rates',
        autoLoad=true,
        fields: ['mainid','Country'],
        proxy : new Ext.data.HttpProxy({
                 method: 'GET',
                 url: '/projectLink/gridData.php'
            })
    });

    var grid = Ext.create('Ext.grid.Panel',{
                    renderTo: 'grid-rates',
                    width:700,
                    height:500,
                    title:"Country",
                    store:store,
                    columns:[
                                {id: 'mainid', header: "mainid", width: 200, sortable: true, dataIndex: 'mainid'},
                                {id: 'Country', header: "Country", width: 200, sortable: true, dataIndex: 'Country'}
                             ]

                });

JSON 存储在向服务器发送请求并发送回数据时被填满,但网格从未填充:( 缺少什么?

按照我正在使用的 JSON:

{"count":"18239",
"rates":[
{"mainid":"75966","Country":"Afghanistan Cellular-AT"},
{"mainid":"75967","Country":"Afghanistan Cellular-AWCC"},
{"mainid":"75968","Country":"Afghanistan Cellular-Areeba"},
{"mainid":"75969","Country":"Afghanistan Cellular-Etisalat"},
{"mainid":"75970","Country":"Afghanistan Cellular-Others"},
{"mainid":"75971","Country":"Afghanistan Cellular-Roshan"},
{"mainid":"75972","Country":"Albania"},
{"mainid":"75973","Country":"Albania Cellular-AMC"},
{"mainid":"75974","Country":"Albania Cellular-Eagle"},
{"mainid":"75975","Country":"Albania Cellular-Plus"}
]}

请帮忙!

【问题讨论】:

  • 您遇到任何错误吗?如果有帮助,请发布错误消息。

标签: javascript json extjs grid store


【解决方案1】:

使用 Ext.data.Store 代替 JsonStore,在 4.0.2a 中测试
我也无法在文档中找到 JsonStore

试试这个:

var store = new Ext.data.Store({ 
    fields:['mainid','Country'],
    proxy: {
        type: 'ajax',
        url : '/projectLink/gridData.php',
        reader: {
            type: 'json',
            root: 'rates',
            totalProperty : "count"
        }
    },
    autoLoad : true
});

【讨论】:

    【解决方案2】:

    我不确定这是否是问题所在,但配置 autoLoad 是错误的。

    你有:autoLoad=true

    应该是:autoLoad : true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多