如何在extjs的列级获取嵌套的json数据

问题描述 投票:1回答:1

我对extjs很新,我听说有一天,请任何人帮忙。

如何在extjs的列级别获取嵌套的json数据对于普通列,它获取的确切,但是当它在col6处的数组列的cums被触发时。

这就是我的模型的样子

json数据如:

[
       {
       "col1" : "abc",
       "col2" : "aasd",
       "col3" : "aasd",
       "col4" : "sad",
       "col5" : "sad",
       "col6" : [
                   {
                      "inncol1": "laksd",
                      "inncol2": "laksd"
                   },
                   {
                      "inncol1": "laksd",
                      "inncol2": "laksd"
                   }
                   ]
       },

        {
       "col1" : "abc",
       "col2" : "aasd",
       "col3" : "aasd",
       "col4" : "sad",
       "col5" : "sad",
       "col6" : [
                   {
                      "inncol1": "laksd",
                      "inncol2": "laksd"
                   },
                   {
                      "inncol1": "laksd",
                      "inncol2": "laksd"
                   }
                   ]
       }

    ]

期待输出:

====================================================================
**col1**    **col2**    **col3**    **col4**    **col5**                **col6  **
                                            ========================            
                                             **inncol1**    **inncol2** 
====================================================================
abc     jasd    asjd    aasd    asdjk        asdjk        asdas
                                             asdas         asdd
=====================================================================
asdas   sada    asdas   sdf     asdas       asdas           sdaas
                                            asds            daass
======================================================================  

型号是:

 Ext.define('MONTHWISEMODEL', 
                            {
                                extend  : 'Ext.data.Model',
                                fields  :
                                [
                                     {  name: 'col1'                }
                                    ,{  name: 'col2'                }
                                    ,{  name: 'col3'                }
                                    ,{  name: 'col4'                }
                                    ,{  name: 'col5'                }
                                    ,{  name: 'col6'                }
                                ]
                            }); 

商店是:

getStore : function()
            {
                var proxy = {
                         type        : 'ajax'
                        ,url         : myurl
                        ,reader      : 'jsonreader'

                return   Ext.create('Ext.data.GridStore',
                            {
                                 model      : 'MONTHWISEMODEL'
                                ,autoLoad   : false
                                ,autoDestroy: false
                                ,proxy      : proxy
                            });
            }   
    }

网格是:

getMonthlyReportGrid : function()
    {

        var me = this;
        var store = me.getStore();
        var reportsGrid =   Ext.create('Ext.custom.grid.Panel', 
        {
             store          : store
            ,id             : 'monthlyGridData'
            ,overflowX      : 'scroll' 
            ,overflowY      : 'scroll'
            ,forceFit       : false
            ,height         : 450
            ,cls            : 'pr-data-grid'
            ,columns        : 
                [
                     {  text : 'col1'                               ,dataIndex : 'col1'             }
                    ,{  text : 'col2'                               ,dataIndex : 'col2'             }
                    ,{  text : 'col3'                               ,dataIndex : 'col3'             }
                    ,{  text : 'col4'                               ,dataIndex : 'col4'                 }
                    ,{  text : 'col5'                               ,dataIndex : 'col5'             }
                    ,{  text : 'col6'                                , columns: [                                                   
                                                                                    ,{ text : 'inncol1'       ,dataIndex : 'inncol1'            }
                                                                                    ,{ text : 'inncol2'       ,dataIndex : 'inncol2'        }
                                                                                ] }
                ]

        });
        return reportsGrid;
    }
extjs
1个回答
0
投票

您可以使用renderer类的Ext.grid.column.Column方法,它可以用作转换器,您可以返回所需的值。这是FIDDLE

© www.soinside.com 2019 - 2024. All rights reserved.