0

我正在尝试将数组值传递给 jqgrid。如下,“排名”值是另一个数组,我想将数组中的每个元素(排名和分数)放在单独的列中:

Javascript:

    $(document).ready(function(){        
        jQuery("#ggp_info").jqGrid('GridUnload');
        jQuery("#ggp_info").jqGrid({
            data: jsonObj.entry, 
            datatype: "local",
            colModel:[
                {name:'id',index:'id', width:55, align:"center"},
                {name:'name',index:'name', width:110, align:"center"},
                {name:'sort',index:'sort', width:50, align:"center"},
                {name:'ranking.rank',index:'ranking.rank', jsonmap:'ranking.rank', width:250, align:"center"}
            ],  
            rowNum:7,
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            height: "100%",
            shrinkToFit: false,
            caption:"Leaderboard"
        }); 
    }); 

jsonObj值如下:

{“入口”:
[{"id":"10000935","name":"Queen","sort":"0","ranking":[{"rank":"1","score":"60"}]} ,
 {"id":"10000936","name":"Level1","sort":"0","ranking":[{"rank":"1","score":"700"}]}]
4

1 回答 1

0

首先,您必须解析您的 json 对象并将其拆分以检索分离的排名和分数然后您必须创建两列,如下所示:

{name:'rank',index:'rank', editoptions:{value:rankArray}}
{name:'scores',index:'scores', editoptions:{value:scoresArray}}

因此,您将在 rankArray 中放入排名,在 scoresArray 中放入分数

于 2012-08-07T12:56:00.853 回答