【问题标题】:Loading data into grid from Form Panel response从表单面板响应将数据加载到网格中
【发布时间】:2011-12-22 18:11:20
【问题描述】:

我有一个带有关联网格的表单,可以满足一对多的关系。 当我使用 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 中的网格数据加载到我的网格中。

请帮忙.. }, “成功”:“真” }

【问题讨论】:

  • *[]* 在 JSON 中?我会删除它们,你对响应做了什么?
  • 其实我是想把它变成斜体。请忽略..我有回复,但我不知道如何将其添加到网格的存储中

标签: javascript extjs


【解决方案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 事件处理程序的一部分自动更新,这些处理程序在您构建网格时由网格附加到存储。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-10
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2011-12-28
      • 1970-01-01
      相关资源
      最近更新 更多