我正在使用 jquery listview 来显示课程名称列表。数据需要从控制器中获取。当我运行它时,页面中没有任何显示。
这是我的html
<div id="courseName">
<ul data-role="listview" data-inset="true" >
</ul>
</div>
这是我的脚本
$('#registeredClasses').live('pageshow', function(){
$.ajax({
url: '${pageContext.request.contextPath}/getRegisteredClassesData.html',
dataType: 'json',
success: function(json_results){
listItems = $('#courseName').find('ul');
$.each(json_results.rows, function(key) {
html = '<li <h3><a href="index1.html?id=' + [json_results.rows[key].courseId] +'"rel="external">'+json_results.rows[key].courseName+'</h3>';
html += '<p><br> Course name: '+json_results.rows[key].courseName+'</p></a></li>';
listItems.append(html);
});
$('#courseName ul').listview('refresh');
$.mobile.pageLoading(true);
}
});
});
这就是它从控制器调用的地方
@RequestMapping(value = "getRegisteredClassesData.html", method = RequestMethod.POST)
public @ResponseBody CustomPagedResultResponse getRegisteredClassesData(
HttpServletRequest request,HttpSession session) {
CustomPagedResultResponse paging = new CustomPagedResultResponse();
log.debug("getRegisteredClassesData.html:");
log.debug("rows:"+request.getParameter("rows"));
log.debug("courseId:"+session.getAttribute("courseId"));
log.debug("page:"+request.getParameter("page"));
log.debug("sidx:"+request.getParameter("sidx"));
log.debug("sord:"+request.getParameter("sord"));
//String loginId = (request.getSession().getAttribute("loginId")).toString();
//String page =(request.getSession().getAttribute("page")).toString();
//String row = (request.getSession().getAttribute("row")).toString();
String page = request.getParameter("page");
int pageSize = new Integer(request.getParameter("rows")).intValue();
StringBuffer condition = new StringBuffer();
if (request.getParameter("sidx") != null && !request.getParameter("sidx").equals("")) {
condition.append(request.getParameter("sidx"));
condition.append(" ");
}
if (request.getParameter("sord") != null && !request.getParameter("sord").equals("")) {
condition.append(request.getParameter("sord"));
}
log.debug("condition: " + condition.toString());
log.debug("page:"+page);
log.debug("row:"+pageSize);
String courseType = "%";
UserProfile userProfile = (UserProfile)session.getAttribute("userProfile");
//////////////////////////////////////////////////////
// Retrieve Total Record first
///////////////////////////////////////////////////////
RegisteredClassesSearch search = new RegisteredClassesSearch();
search.setLanguage("ENU");
search.setLoginRowId(userProfile.getContactRowId());
search.setRegNo(null);
search.setAction("1");
search.setCourseType(courseType);
search.setPage(null);
search.setPageSize(null);
search.setOrderBy(null);
Integer recordCount = registeredClassesService.getTotalAccounts(search);
log.debug("*****Training Controller Total record:"+recordCount);
System.out.println("*****Training Controller Total record:"+recordCount);
//////////////////////////////////////////////////////
// Retrieve Total Record first
///////////////////////////////////////////////////////
if(recordCount>0){
System.out.println("******** Login Id:"+userProfile.getContactRowId());
System.out.println("******** Course Type:"+courseType);
System.out.println("******** Page Size:"+pageSize);
System.out.println("******** Page:"+page);
System.out.println("******** Order By:"+condition);
List<RegisteredClassesTest> registeredClassesView = registeredClassesService.getAccounts(search);
paging.setRows(registeredClassesView);
}else{
paging.setRows(null);
}
paging.setRecords(String.valueOf(recordCount));
paging.setPage(page);
int total = recordCount % pageSize == 0 ? recordCount / pageSize : recordCount / pageSize + 1;
paging.setTotal(String.valueOf(total));
return paging;
}