Home Web Front-end JS Tutorial Example sharing of MUI implementation of pull-up loading and pull-down refresh

Example sharing of MUI implementation of pull-up loading and pull-down refresh

May 25, 2018 am 10:07 AM
drop down Example

This article mainly introduces the pull-up loading and pull-down refresh effects of MUI to everyone in detail. It has certain reference value. Interested friends can refer to it.

The examples in this article share MUI with everyone. The specific code to implement pull-up loading and pull-down refresh display is for your reference. The specific content is as follows

WritingStored ProcedurePaging(T-SQL is used here)

CREATE PROC [dbo].[Common_PageList]
(
@tab nvarchar(max),---表名
@strFld nvarchar(max), --字段字符串
@strWhere varchar(max), --where条件 
@PageIndex int, --页码
@PageSize int, --每页容纳的记录数
@Sort VARCHAR(255), --排序字段及规则,不用加order by
@IsGetCount bit --是否得到记录总数,1为得到记录总数,0为不得到记录总数,返回记录集
)
AS
declare @strSql nvarchar(max)
set nocount on;
if(@IsGetCount = 1)
begin
 set @strSql='SELECT COUNT(0) FROM ' + @tab + ' WHERE ' + @strWhere
end
else
begin
 set @strSql=' SELECT * FROM (SELECT ROW_NUMBER() 
 OVER(ORDER BY ' + @Sort + ') AS rownum, ' + @strFld + ' FROM ' + @tab + ' where ' + @strWhere + ') AS Dwhere
 WHERE rownum BETWEEN ' + CAST(((@PageIndex-1)*@PageSize + 1) as nvarchar(20)) + ' and ' + cast((@PageIndex*@PageSize) as nvarchar(20))
end

print @strSql
exec (@strSql)

set nocount off;
Copy after login

webApi interface (ADO.NET is partially encapsulated, here is the calling form)

/// 测试mui下拉刷新
    /// </summary>
    /// <param name="flag"></param>
    /// <returns></returns>
    [HttpPost]
    public object test(JObject data)
    {

      using (var db = new DbBase())
      {
        SqlParameter[] arr = { 
                   new SqlParameter{ ParameterName="tab",Value=data["tab"].ToString()},
                   new SqlParameter{ ParameterName="strFld",Value=data["strFld"].ToString()},
                   new SqlParameter{ ParameterName="strWhere",Value=data["strWhere"].ToString()},
                   new SqlParameter{ ParameterName="PageIndex",Value=Convert.ToInt32(data["PageIndex"])},
                   new SqlParameter{ ParameterName="PageSize",Value=Convert.ToInt32(data["PageSize"])},
                   new SqlParameter{ ParameterName="Sort",Value=data["Sort"].ToString()},
                   new SqlParameter{ ParameterName="IsGetCount",Value=Convert.ToInt32(data["IsGetCount"])},
                   };


      return  RepositoryBase.ExecuteReader(db, "Common_PageList", arr);


      }
Copy after login

Page implementation

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <title>Hello MUI</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="../css/mui.min.css" rel="external nofollow" >
    <style type="text/css">
      
       
    </style>
  </head>
  <body>
    
      <header class="mui-bar mui-bar-nav">
      <h1 class="mui-title">下拉刷新(单webview模式)</h1>
    </header>
    
    <p id="pullrefresh" class="mui-content mui-scroll-wrapper">
      <p class="mui-scroll">
        
          <ul id="container" class="mui-table-view mui-table-view-chevron"></ul>
      
      </p>
    </p>
     <ul id="temp" class="mui-table-view" style="display: none;">
         <li class="mui-table-view-cell">
           <a class="mui-navigate-right">
             @name
           </a>
         </li>
        
       </ul>
    
    <script src="../js/mui.js" type="text/javascript" charset="utf-8"></script>
    <script>
  
        /**
         数据源分页参数对象
         * */
        var obj={ tab:&#39;SystemUsers&#39;,
              strFld:&#39;code,Username&#39;,
              strWhere:&#39;1=1&#39;,
              PageIndex:1,
              PageSize:10,
              Sort:&#39;Username&#39;,
              IsGetCount:0,
              pageCount:0
            }
        
      //webApi服务器接口  
      var apiUrl="http://192.168.200.114:8123/api/Common/Base/test";
      
      
        /**
         * 定义数据源按什么html方式展示,动态生成html字符串的逻辑
         **/        
        var drawHtml=function(data){
            var html=""
             for (var i=0;i<data.length;i++) 
             {
              var temp=document.getElementById("temp").innerHTML; //模板
              html+=temp.toString().replace(&#39;@name&#39;,data[i].Username); //替换参数叠加
            }
             
           return html;
        }
    
      mui.ready(function(){
       /**
         MUI配置项
         * */    
      mui.init({
        pullRefresh: {
          container: &#39;#pullrefresh&#39;,
          down: {
            callback: pulldownRefresh
          }, //END 下拉刷新
          up : {  
             contentrefresh : "正在加载...",//可选,正在加载状态时,上拉加载控件上显示的标题内容
             contentnomore:&#39;没有更多数据了&#39;,//可选,请求完毕若没有更多数据时显示的提醒内容;
             callback :pullupRefresh //必选,刷新函数,根据具体业务来编写,比如通过ajax从服务器获取新数据;
          } //END 上拉加载
        }
      });
             
        //统计:数据总数、分页总数  
        obj.IsGetCount=1;           
        loadData(apiUrl,obj,0);
       
        //初始化列表数据(第一页)
        obj.IsGetCount=0;    
         loadData(apiUrl,obj,0,"down",function(data){           
           //此处实现动态绘制DOM的逻辑,根据数据源自行处理要展示的html方式                     
           return drawHtml(data);
           
         });
        
        
      });
             
      /*
       读取数据源
       url:api地址
       dataObj:数据源分页查询参数对象
       Timeout:指定多少时间后绘制页面DOM展示对象,
               动态生成的元素代码包含在一个setTimeout函数里,
               用  setTimeout,主要对于下拉刷新间隔时间
       loadType:加载方式:up(上拉加载)、down(上拉刷新)    
       drawFunction:回调函数,处理拿到数据源,绘制DOM展示界面的html
                   ,要接收返回的html字符串
       * */
      
      var loadData=function(url,dataObj,Timeout,loadType,drawFunction){
        
        mui.ajax(url, {
                type: "post",
                data:dataObj,
                async:false,
                headers: {&#39;Content-Type&#39;: &#39;application/json&#39;},
                success: function(data) {
                    
                  //统计出数据总数
                  if(dataObj.IsGetCount==1)
                  {                                    
                    obj.pageCount=Math.ceil(parseInt(data[0].Column1)/obj.PageSize) ;                   
                     return;
                  }
          
                  setTimeout(function() {      
                                   
                  //动态绘制出的Dom元素,结合数据展现
                  var html=  drawFunction(data);
                     
                  if(loadType=="up")  //上拉加载
                  {
                        if(obj.PageIndex==obj.pageCount)
                        {
                          //参数为true代表没有更多数据了。
                          mui(&#39;#pullrefresh&#39;).pullRefresh().endPullupToRefresh(true);
                        }
                        else
                        {
                          mui(&#39;#pullrefresh&#39;).pullRefresh().endPullupToRefresh(); 
                        }
                      
                    //将下一页数据追加到容器  
                    document.getElementById("container").innerHTML=document.getElementById("container").innerHTML+html;
                  }
                  else if(loadType=="down") //下拉刷新
                  {
                    // 该方法的作用是关闭“正在刷新”的样式提示,内容区域回滚顶部位置
                    mui(&#39;#pullrefresh&#39;).pullRefresh().endPulldownToRefresh(); 
                    
                    //将第一页数据覆盖到容器
                    document.getElementById("container").innerHTML=html;
                    
                    //启用上拉加载
                    mui(&#39;#pullrefresh&#39;).pullRefresh().enablePullupToRefresh();
                     
                  } 
                  
                }, Timeout);//END setTimeout();
      
                },//END success();
                
                error: function(xhr, type, errorThrown) {                 
                      console.log(type);
                }//END error();
                
          });//END ajax();
        
      }//END loadData();
            
     /**
       * 下拉刷新具体业务实现
       */
      function pulldownRefresh() {  
          console.log(&#39;重置数据,初始到第一页&#39;);
          obj.PageIndex=1;
  
           loadData(apiUrl,obj,1000,"down",function(data){
           //此处实现动态绘制DOM的逻辑,根据数据源自行处理要展示的html方式                     
           return drawHtml(data);
             
           });
    
    } //END pulldownRefresh() 下拉刷新函数
        
  
      /**
       * 上拉加载具体业务实现
       */
      function pullupRefresh() {
        obj.PageIndex++;//当前页累加,加载下一页的数据       
        console.log("加载第:"+obj.PageIndex+"页");
        console.log("页总数:"+obj.pageCount);
          
       loadData(apiUrl,obj,1000,"up",function(data){
           //此处实现动态绘制DOM的逻辑,根据数据源自行处理要展示的html方式                     
           return drawHtml(data);
           
       });
        

      }
      
    

    </script>
  </body>

</html>
Copy after login

The above is the detailed content of Example sharing of MUI implementation of pull-up loading and pull-down refresh. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SVM examples in Python SVM examples in Python Jun 11, 2023 pm 08:42 PM

Support Vector Machine (SVM) in Python is a powerful supervised learning algorithm that can be used to solve classification and regression problems. SVM performs well when dealing with high-dimensional data and non-linear problems, and is widely used in data mining, image classification, text classification, bioinformatics and other fields. In this article, we will introduce an example of using SVM for classification in Python. We will use the SVM model from the scikit-learn library

VUE3 Getting Started Example: Making a Simple Video Player VUE3 Getting Started Example: Making a Simple Video Player Jun 15, 2023 pm 09:42 PM

As the new generation of front-end frameworks continues to emerge, VUE3 is loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player. 1. Install VUE3 First, we need to install VUE3 locally. Open the command line tool and execute the following command: npminstallvue@next Then, create a new HTML file and introduce VUE3: &lt;!doctypehtml&gt;

Learn best practice examples of pointer conversion in Golang Learn best practice examples of pointer conversion in Golang Feb 24, 2024 pm 03:51 PM

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

PHP simple web crawler development example PHP simple web crawler development example Jun 13, 2023 pm 06:54 PM

With the rapid development of the Internet, data has become one of the most important resources in today's information age. As a technology that automatically obtains and processes network data, web crawlers are attracting more and more attention and application. This article will introduce how to use PHP to develop a simple web crawler and realize the function of automatically obtaining network data. 1. Overview of Web Crawler Web crawler is a technology that automatically obtains and processes network resources. Its main working process is to simulate browser behavior, automatically access specified URL addresses and extract all information.

VAE algorithm example in Python VAE algorithm example in Python Jun 11, 2023 pm 07:58 PM

VAE is a generative model, its full name is VariationalAutoencoder, which is translated into Chinese as variational autoencoder. It is an unsupervised learning algorithm that can be used to generate new data, such as images, audio, text, etc. Compared with ordinary autoencoders, VAEs are more flexible and powerful and can generate more complex and realistic data. Python is one of the most widely used programming languages ​​and one of the main tools for deep learning. In Python, there are many excellent machine learning and deep

The relationship between the number of Oracle instances and database performance The relationship between the number of Oracle instances and database performance Mar 08, 2024 am 09:27 AM

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

Verification code usage examples in Gin framework Verification code usage examples in Gin framework Jun 23, 2023 am 08:10 AM

With the popularity of the Internet, verification codes have become a necessary process for login, registration, password retrieval and other operations. In the Gin framework, implementing the verification code function has become extremely simple. This article will introduce how to use a third-party library to implement the verification code function in the Gin framework, and provide sample code for readers' reference. 1. Install dependent libraries Before using the verification code, we need to install a third-party library goCaptcha. To install goCaptcha, you can use the goget command: $goget-ugithub

GAN algorithm example in Python GAN algorithm example in Python Jun 10, 2023 am 09:53 AM

Generative Adversarial Networks (GAN) is a deep learning algorithm that uses two neural networks to compete with each other to generate new data. GAN is widely used for generation tasks in image, audio, text and other fields. In this article, we will use Python to write an example of a GAN algorithm for generating images of handwritten digits. Dataset Preparation We will use the MNIST data set as our training data set. The MNIST data set contains

See all articles