0

我正在使用 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;
}
4

3 回答 3

0
  try this one,

你应该关闭<li>标签,你确定数据来自服务器吗?

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));
于 2012-05-23T03:11:56.463 回答
0

使用 json_results.d 而不是 json_results.row。

 $.each(json_results.d, function(index, item) { 

html = '<li > <h3><a href="index1.html?id=' + item.courseId+'"rel="external">'+ item.courseName+'</h3>';
  html += '<p><br> Course name: '+item.courseName+'</p></a></li>';

}

于 2012-05-23T07:42:22.517 回答
0

谢谢,我已经成功了..这是我的脚本。对于数据,我先对其进行硬编码..

$('#registeredClasses').live('pageshow', function(){
    var rowInput = "1";
    var pageInput = "1";

    $.ajax({
     url: '${pageContext.request.contextPath}/getRegisteredClassesDetails.html',
     data: ( {rows : rowInput , page : pageInput}),
     type: 'POST',

    success: function(json_results){
        $('#list').append('<ul data-role="listview" data-inset="true"</ul>');
        listItems = $('#list').find('ul');
        $.each(json_results.rows, function(key) {
          html = '<li <h3><a href="${pageContext.request.contextPath}/getRegisteredClassesDetails.html?id=' + [json_results.rows[key].courseId] 
                +'"rel="external">'+json_results.rows[key].courseName+'</h3>';
        listItems.append(html);
        });

    $('#list ul').listview();
    $.mobile.pageLoading(true);      
    }
});
});
于 2012-05-24T01:29:24.703 回答