无法使用JSON结果将数据呈现到网格列中 [英] Unable to render data into grid column using JSON results

查看:158
本文介绍了无法使用JSON结果将数据呈现到网格列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的网格存储.

I have a grid store with something like this.

var gridStore = Ext.create('Ext.data.Store',{
    proxy : {
        type : 'ajax',
        actionMethods : {
            read : 'POST'
        },
        url : 'getECIAgentWrapperJobs.do',
        reader : {
            type : 'json',
            rootProperty : 'rows',
            totalProperty : 'results'
        }
    },
    pageSize : 3,
    autoLoad : {start: 0, limit: 3}
});

很明显,它向URL发出AJAX请求. 我为此商店获得的JSON响应如下所示:

Clearly it makes an AJAX request to the url. The JSON response that I am getting for this store looks something like this :

{  
   "results":2,
   "rows":[  
      {  
         "pkTable1":1,
         "name":"Rick",
         "eciAgentJob":{  
            "pkTable2":11,
            "name":"Play Local Ar",
         },
      }
   ],
   "msg":null,
   "success":true,
}

现在这是我的网格的外观:

Now this is how my grid looks :

var mappedEciAgentJobsGrids = Ext.create('Ext.grid.Panel',{
        store : gridStore,
        columns : [
            {
                dataIndex : 'pkTable1',
                header : 'Pk of table 1'
            },
            {
                dataIndex : 'name',
                header : 'Name'
            },
            {
                dataIndex : 'eciAgentJob.pkTable2',
                header : 'Pk of Table 2'
            }
        ]
    });  

现在在我的UI中,前2列(分别具有dataIndex:pkTable2和name)可以正常加载.但是对于第三个来说,它不是. 我知道这是因为我已经使用dataIndex作为'eciAgentJob.pkTable2'.但是,当我们像我那样获得响应时,将数据加载到列中的方式是什么(其中eciAgentJob是原始JSON中的对象). 请帮忙.

Now in my UI the first 2 columns(with dataIndex: pkTable2 and name respectively) load fine. But for the 3rd one it does not. I know it is because I have used dataIndex as 'eciAgentJob.pkTable2'. But then what is that way to load data in columns when we get response like the way I got(where eciAgentJob is a object inside the original JSON). Please help.

由于其他一些用例原因,我不想使用渲染器.

Edit : I dont want to use a renderer due to some other use case reasons.

推荐答案

在模型中定义一个新字段,并使用必填字段进行映射.在转换功能中,从记录中选择任何值.

Define a new field in your model and map with the required field. In convert function pick any value from the record.

 Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'name', type: 'string ' },
        {
         name: 'columnName',

         convert: function (value, record) {
             return "return what ever you want"
         }
     }

    ]
});

这篇关于无法使用JSON结果将数据呈现到网格列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆