【问题标题】:json array does not show in extjs gridjson 数组未显示在 extjs 网格中
【发布时间】:2012-08-22 15:01:01
【问题描述】:

我使用以下 Ext 函数从 json 数组绑定 ext 网格中的值。我从 URL 获取 json 数组。它可以正常工作,这意味着我得到了值。我的问题是如果我尝试绑定 Extjs 网格中的值我无法在该网格中添加 json 数组值。如何解决这个问题?

Ext.onReady(function(){

    var proxy=new Ext.data.HttpProxy({url:'http://someurl'});

    var reader=new Ext.data.JsonReader({},[
          {name: 'User_Id', mapping: 'User_Id'},
          {name: 'First_Name', mapping: 'First_Name'},            
          {name: 'Last_Name', mapping: 'Last_Name'}, 
          {name: 'Notes', mapping: 'Notes'} 
     ]);
     //alert(reader);
     var store=new Ext.data.Store(    {
         proxy:proxy,
         reader:reader
     });

    store.load();


    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {header: "User_Id", width: 60, dataIndex: 'User_Id', sortable: true},
            {header: "First_Name", width: 60, dataIndex: 'First_Name', sortable: true},
            {header: "Last_Name", width: 60, dataIndex: 'Last_Name', sortable: true},
                           {header: "Notes", width:80, dataIndex: 'Notes', sortable: true}

        ],
        renderTo:'example-grid',
        width:2000,
        height:1000
    });

});

【问题讨论】:

    标签: extjs store jsonstore loaddata


    【解决方案1】:

    您能否发布您从“http://someurl”获得的 JSON 响应?

    我希望您的 JSON 响应包含以下键“User_Id”、“First_Name”、“Last_Name”、“Notes”的键值对。

    【讨论】:

    • { "ResponseCode": "111", "ResponseMessage": "Success", "Values": [ { "User_Id": 1, "First_Name": "abcd", "Last_Name": " efgh", "Notes": null } ] }
    • 您需要在商店的配置中设置root: 'Values'
    【解决方案2】:

    ExtJS 需要这样的 json 响应:

    {
        "ResponseCode": "111",
        "success": true,
        "total": 1,
        "data": [{
            "User_Id": 1,
            "First_Name": "abcd",
            "Last_Name": "efgh",
            "Notes": null
        }]
    }​
    

    【讨论】:

      猜你喜欢
      • 2012-12-28
      • 2013-08-26
      • 2012-05-05
      • 1970-01-01
      • 2012-06-20
      • 2011-09-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多