mui pullrefresh 下拉刷新 上拉加载

<script>
    mui.init({
        pullRefresh: {
            container: '#pullrefresh',
            down: {
                style:'circle',
                callback: pulldownRefresh
            },
            up: {
                //auto:true,
                contentrefresh: '正在加载...',
                callback: pullupRefresh
            }
        }
    });
    var count = 1;
    function pullupRefresh() {
     var pageTotal = $("#pageTotal").val(); //页码的总数
     var pageNum = pageTotal % 5 == 0 ? parseInt(pageTotal / 5) : Math.ceil(pageTotal / 5);  //分页
     count = parseInt(count)+1;
     if(count > pageNum){
      return false;
     }
        setTimeout(function() {
            mui('#pullrefresh').pullRefresh().endPullupToRefresh((count >= pageNum)); //参数为true代表没有更多数据了。
            refreshData('up','dimension',count);

        }, 1500);
    }
    /**
     * 下拉刷新具体业务实现
     */
    function pulldownRefresh() {
     var pageTotal = $("#pageTotal").val();
     var pageNum = pageTotal % 10 == 0 ? parseInt(pageTotal / 10) : Math.ceil(pageTotal / 10);
     count = parseInt(count)+1;
     if(count > pageNum){
      return false;
     }
        setTimeout(function() {
            refreshData('down','dimension',count)
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            mui.toast("有新内容,已刷新!");
        }, 1500);
    }
</script>


function refreshData(direction, urlId, pageNo) {
    var direction = direction;
    url = ''
    if(urlId == "categoryId"){
     var id = mGetUrlParam('categoryId');
     url = 'url?categoryId='+id+'&pageNo='+pageNo
    }
    if(urlId == "dimension"){
     var id = mGetUrlParam('dimension');
     url = 'url?categoryId='+id+'&pageNo='+pageNo
    }
    var table = document.body.querySelector('.mui-table-view');
    mui.ajax({
         url: url,
         type: "GET",
         dataType : "json",
         success:function (data) {
          console.log(data)
          var data = data.page.content
         for (var i = 0; i<data.length; i++){
             var li = document.createElement('li');
             li.className = 'mui-table-view-cell';
             li.innerHTML = ''+data[i].title+'';
             if(direction == "up"){
                 table.appendChild(li);
             }
             if(direction == "down"){
                 table.insertBefore(li, table.firstChild);
             }
         }
         }
     })
}

你可能感兴趣的:(Mui)