1

将数据从动作加载到 jqGrid 时出现问题

我的操作返回 JSON 数据:

{"page":"1","records":"31","rows":["{'id':'1','cell':['1','Cant open destop','Destop','Easy','duongls','huyld','minhnq','Finance ','Open']}","{'id':'2','cell':['2','Cant log to email','Email','Normal','thangtd','minhnq','longnh','Secretary ','Assigned']}","{'id':'3','cell':['3','No internet access Edited ver 2 longnh','Connection','Hard','thangtd','longnh','longnh','Secretary ','Closed']}","{'id':'4','cell':['4','Request password','Account','Normal','dungtq','honglm','longnh','Director','Cancelled']}","{'id':'5','cell':['5','Cant open latop','Laptop','Hard','duongls','huyld','minhnq','Director','Closed']}","{'id':'6','cell':['6','issue 11111111111111','','','dungtq','longnh','','Planning','Open']}","{'id':'7','cell':['7','Issue ku minh heo','','','dungtq','longnh','','Planning','Open']}","{'id':'8','cell':['8','New ticket 12345','','','dungtq','longnh','','Planning','Open']}","{'id':'9','cell':['9','Mail server cannot connect','','','haitct','longnh','','Director','Open']}","{'id':'10','cell':['10','aaaaaaaaaaaa','','','dungtq','longnh','','Planning','Open']}"],"total":"4"}

在 JSP 中我调用 jqgrid:

$("#list1").jqGrid({                  
        url: "<%=request.getContextPath()%>/pagingIssue?time='+new Date().getTime()",
        colNames:['Id','Name', 'Type','Severity', 'Owner','Register', 'Responsor', 'Department','Status'],
        colModel:[
               {name:'issId',index:'issId', width:40,sortable:true},
               {name:'issName',index:'issName', width:200,sortable:true},
               {name:'issType',index:'issType', width:100,sortable:true},
               {name:'issSeverity',index:'issSeverity', width:100,sortable:true},
               {name:'issOwner',index:'issOwner', width:80,sortable:true},
               {name:'issRegister',index:'issRegister', width:100,sortable:true},
               {name:'issResponsor',index:'issResponsor', width:100,sortable:true},
               {name:'department',index:'department', width:120,sortable:true},
               {name:'issStatus',index:'issStatus', width:80,sortable:true}],
       rowNum:10,
       rowList:[10,15,20],
       pager: '#pager1',
       sortname: 'issId',
       datatype: 'json',
       recordpos: 'left',
       viewrecords: true,
       sortorder: 'desc',
       multiselect: true,
       caption: 'Issue List' });
});

网格只显示加载中...你能帮帮我吗?

4

1 回答 1

2

默认情况下,您的 JSON 数据应采用 JSON 数据的 jqGrid 文档中注明的格式

{ 
  "total": "xxx", 
  "page": "yyy", 
  "records": "zzz",
  "rows" : [
    {"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
    {"id" :"2", "cell":["cell21", "cell22", "cell23"]},
      ...
  ]
}

您的数据很接近,但rows包含一个字符串

"rows":["{'id' ... ]}"]

而不是一个对象:

"rows":[{'id' ... ]}]

此外,您应该始终对字符串使用双引号,而不是单引号(有关更多详细信息,请参阅json.org上的状态机图)。所以你的 JSON 应该是这样的:

"rows":[{"id" ... ]}]
于 2012-06-26T18:13:06.043 回答