带有spring mvc的jqgrid json数据类型

时间:2011-03-22 02:24:44

标签: json jqgrid

我是jqgrid的新手,我试图模拟上面的代码,但它不起作用。在服务器端,我创建了类

public class TaskBean {
String orderId;
String realty;
String building;
String priority;
String action;
String assignee; // add getter/setter methods
}

TaskBeanList.java

public class TaskBeanList {
private String page;
private String total;
private String records;
private List<TaskBean> rows;
}

Spring Controller Code

@RequestMapping("/page4.htm")
public @ResponseBody TaskBeanList   getJQGridData(HttpServletRequest request, HttpServletResponse response) {
System.out.println("xml data");
List<TaskBean> taskList = new ArrayList<TaskBean>();
   taskList.add(new TaskBean("Task1", "K-CY-329", "144", "G-3", "1", "Pending", "XYZ"));
    taskList.add(new TaskBean("Task2", "K-CY-356", "165", "A-10", "4", "Closed", "ABC"));
    taskList.add(new TaskBean("Task3", "K-CY-343", "768", "B-12", "3", "Pending", "IJK"));
    taskList.add(new TaskBean("Task4", "K-CY-786", "918", "F-9", "2", "Open", "PQR"));
    TaskBeanList tsklst = new TaskBeanList("1", "5", "20", taskList); 
    return tsklst; 
}

客户端JQGrid JS代码

jQuery(document).ready(function(){ 
jQuery("#list3").jqGrid({
autowidth: true,
datatype : "json",
url: "http://localhost:8080/SpringMVC/page4.htm",
mtype: 'get',
colNames : ["Title","Order ID","Realty","Building",
        "Priority","Action","Assignee"],
colModel : [
{label: "Title",   name: "title",   index: "Title", jsonmap: "orderId"},
{label: "OrderID", name: "orderId", index: "OrderID", jsonmap: "orderId"},
{label: "Realty",  name: "realty",  index: "Realty",  jsonmap: "realty" },
{label: "Building",name: "building",index: "Building",jsonmap: "building"},
{label: "Priority",name: "priority",index: "Priority",jsonmap: "priority"},
{label: "Action",  name: "action",  index: "Action",  jsonmap: "action"  },
{label: "Assignee",name: "assignee",index: "Assignee",jsonmap: "assignee"}
],
sortname : "Title",
sortorder : "desc",
shrinkToFit: true,
viewrecords: true,
jsonReader : {
  root: "rows",
  page: "page",
  total: "total",
  records: "records",
  repeatitems: false,
  cell: "cell",
  id: "id",
  userdata: "userdata",
  subgrid: {root:"rows", 
        repeatitems: true, 
        cell:"cell"
      }       
}
}); });

任何人都可以帮忙解决这个问题吗?当我看到jqgrid示例代码时,看起来很简单,但我没有看到任何输出。输出页面为空。请帮助解决。

由于

2 个答案:

答案 0 :(得分:0)

我建议你先看看下面的教程:

http://krams915.blogspot.com/2010/12/jqgrid-and-spring-3-mvc-integration.html

上的jqGrid和Spring 3 MVC集成教程

您可以从该教程中找到答案,或者至少它会改进您正在寻找的内容。

答案 1 :(得分:0)

@ user669789首先要浏览克里斯提到过的krams教程。我也是jqgrid的新手,但是这个教程和源代码对我帮助很大。另一种选择是根据你在jqgrid中的jsonreader使用硬编码的json值。看看它是否填充了。看看this example by Oleg

尝试将其写入printwriter并通过URL调用天气来获取json输出