我想使用jqGrid加载以下json对象。我该怎么做?

时间:2017-09-21 11:40:42

标签: jquery json jqgrid

我想使用jqGrid加载以下json对象。我该怎么做?

{"cell":
 [[
  {"address":"usa","age":22,"id":1,"laptop":"yes","name":"ram","salary":12234},
  {"address":"xyz,","age":25,"id":6,"laptop":"yes","name":"abc ","salary":23889}
 ]]
}

这是我尝试过的。我没有使用jsonmap就试过了。我无法找到错误。请有人帮助我。

$(document).ready(function(){
$("#datatable").jqGrid({
    url:"${pageContext.request.contextPath}/employeesList",
    datatype:"json",
    mtype: "GET",
    colNames:["address","age","id","laptop","name","salary"],
    colModel:[
                {name:"address",index:"address",jsonmap:" cell.address", width:60},
                {name:"age",index:"age", width:90,jsonmap:" cell.age",},
                {name:"id",index:"id", width:100,jsonmap:" cell.id",},
                {name:"laptop",index:"laptop", width:80, align:"right",jsonmap:" cell.laptop",},
                {name:"name",index:"name", width:80, align:"right",jsonmap:" cell.name",},      
                {name:"salary",index:"salary", width:80,align:"right",jsonmap:" cell.salary",}      
            ],  
            rownumbers: true,
            rownumWidth: 40,
            gridview: true,
            jsonReader : {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",  
                repeatitems: false,
               },     
            caption: "Data"
});
});

控制器部分

  public @ResponseBody JSONObject listEmployees() {
        Map<String, Object> modelMap = new HashMap<String, Object>(); 
  modelMap.put("employees",
  prepareListofBean(employeeService.listEmployeess()));
          JSONObject json = new JSONObject();
            JSONArray jsonarray=new JSONArray();
           for (Entry<String, Object> entry : modelMap.entrySet())
        {
            String key = entry.getKey();
           Object value = entry.getValue();
             jsonarray.add(value);
         }
        json.put("cell", jsonarray);
       return json;
      }

0 个答案:

没有答案