我是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控制器代码
@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示例代码时,看起来很简单,但我看不到任何输出。输出页面为空。请帮助解决。
谢谢
发布于 2011-03-22 11:50:38
我建议你先看看下面的教程:
http://krams915.blogspot.com/2010/12/jqgrid-and-spring-3-mvc-integration.html上的jqGrid和Spring3MVC集成教程
你可能会从那篇教程中找到答案,或者至少它会完善你正在寻找的东西。
发布于 2011-03-24 09:18:35
@user669789首先看一下chris提到的kram教程。我对jqgrid也是个新手,但是那个教程和源码帮我找到了一个lot.another替代方案,那就是根据jqgrid中的jsonreader使用硬编码的json值,看看z是否被填充了。在this example by Oleg上看看
尝试将其写入printwriter,看看是否可以通过URL调用它来获得json输出
发布于 2016-12-05 14:58:22
在控制器中,您可以尝试将列表转换为Json.That,如果所有列名都匹配,Json值将直接绑定到JQGrid
控制器类
@RequestMapping("/page4.htm")
public @ResponseBody String 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);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String result = gson.toJson(tsklst );
return result;
}下载gson.jar,然后尝试
它在me.You上的工作也可以参考这里的示例项目
http://www.jriyazahamed.blogspot.com/
https://stackoverflow.com/questions/5386060
复制相似问题