2011-11-05 20 views
0

我有一个表格,其中包含一个关联的网格,用于处理一对多关系。 当我使用URL然后我也使用以下代码获取网格数据加载形式从表单面板响应中将数据加载到网格中

this.load({ 
     url:reportURL + 'editReport', 
     waitMsg:'Loading...', 
     params:{ 
      reportIdKey: this.reportId 
     }, 
     success:function(form,action){     
      response = action.result.data; // Contains the data for the grid    
     } 
    }) 

返回的JSON是如下

{ 
"data":{ 
    "setupDt":"09-27-2011", 
    "expireDt":"12-31-1950", 
    "reportNm":"Report_55283", 
    "templateNm":"risk_measures_tmpl", 
    "GridData": 
    *[ 
    { 
     "sId":1, 
     "sNm":"W", 
     "mId":1, 
     "mNm":"R", 
     "pId":"..", 
     "pIdAlias":"", 
     "bId":"...", 
     "bIdAlias":"", 
     "pDesc":"FUND==GB|ACT==WG|W", 
     "grpId":"", 
     "scF":"", 
     "sortSeq":1, 
     "grpN":1 
    } 
    ]*  

如何可以从上面的JSON加载网格数据进入我的网格。

请帮助.. }, “成功”: “真正的” }

+0

'* ['和'] *'在JSON中?我会删除它们,以及您对响应做了什么? – bensiu

+0

其实我试图把它做成斜体。请忽略..我有我的反应,但我不知道如何将它添加到网格的存储 – Rohit

回答

1

ExtJS的电网使用商店更新的网格。该商店实际上是必需的。您可以使用json store。当您收到回复时,您会收到致电loadData的商店。您使用loadData而不是load的原因是因为表单已经完成了AJAX调用,并且load将尝试再次完成。例如(这一切都假定ExtJS的3.4,我不知道你使用的是什么版本,但它几乎是在ExtJS的4同样的事情):

var gridStore = new Ext.data.JsonStore({ 
     root: 'GridData', 
     fields: [ 
      'sid', 
      // ... your other field names under 'GridData' 
     ] 
    }); 
    var myGrid = new Ext.grid.GridPanel({ 
     store: gridStore, 
     // ... your other config options here 
    }); 
    this.load({ 
     url:reportURL + 'editReport', 
     waitMsg:'Loading...', 
     params:{ 
      reportIdKey: this.reportId 
     }, 
     success:function(form,action){     
      response = action.result.data; // Contains the data for the grid 
      gridStore.loadData(response); 
     } 
    }); 

一旦loadData完成,网格将自动更新为正常load事件处理程序的一部分,这些事件处理程序在构建网格时由网格附加到存储区。

0

我已经通过迭代结果json并在store.getRecordType({field:value})中设置相应的属性。

相关问题