【问题标题】:listview("refresh") is not working for jquery mobilelistview("refresh") 不适用于 jquery mobile
【发布时间】:2013-08-01 21:10:01
【问题描述】:

我必须通过 ajax 调用在 jquery mobile 中的模板中附加数据,我正在使用以下库和 listview 函数来引用现有的 listview("refresh") 函数,但它显示 js 错误,即 listview 不是函数,而函数存在于以下库中:

<script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>

这是我用过的

jQuery(document).ready(function () {
 jQuery('.pagination_ajax_request').click(function () {
     jQuery.ajax({
         type: 'POST',
         url: this.href,
         dataType: 'html',
         data: 'pagination_ajax_request=1',
         success: function (response) {

             // check if <div id="pagination"><div> exist, means ajax resopnse from post listing page other wise ajax resopnse from topic listing page
             if (jQuery("#pagination").length) {
                 jQuery("#pagination").append(response);
             } else {
                 jQuery("#topic_list").append(response);
                 jQuery("#topic_list").listview("refresh");
             }
             if (ajax_pagination_data['current_page'] != ajax_pagination_data['total_pages'] && ajax_pagination_data['current_page'] != '0') {
                 //update "Load More Topics" OR "Load More Posts" link href value
                 var href = jQuery(".pagination_ajax_request").attr('href');
                 jQuery(".pagination_ajax_request").attr('href', href.replace(/&?trail=\d+/, '&trail=' + ajax_pagination_data['trail']));
             } else {
                 //hide "Load More Topics" OR "Load More Posts" if No topic OR post
                 jQuery(".pagination_ajax_request").hide();
             }
         },
         error: function (xhr, textStatus, errorThrown) {
             alert('An error occurred while processing your request.\n' + textStatus + ': ' + errorThrown);
         }
     });
     return false;
  });
});

【问题讨论】:

  • 我们需要先查看您的代码,然后我们才能为您提供帮助。
  • 确保在加载完所有内容后调用它,即。 e.里面 $(function(){ .. }); (或之后)
  • 响应中返回了什么? (成功:函数(响应))
  • 我们以
  • 标记的形式获取数据,所需数据必须附加到现有的
      中。
  • #topic-listdiv 还是 ul?
  • 标签: listview jquery-mobile


    【解决方案1】:

    您从服务器获得的数据在这里很重要。在列表视图中添加动态内容是example

    我认为你在添加 li 时错过了一些元素或某些东西

     $('<li>').append('<a href="#">Mercedes</a>').appendTo('#test-listview');
    

    或者你可以试试

    var UI = $('#listViewID');
    for(x in data){
       UI.append(data);
    }
    $('#listViewID').listview("refresh");
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。我恢复到 jquery v1.8.3 并解决了这个问题。

      您可以在这里尝试 1.8.3 和 1.3.1 的组合:http://jsfiddle.net/dPwzE/

      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script
      <script type="text/javascript" src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
      

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签