微信小程序 實(shí)現(xiàn)列表刷新的實(shí)例詳解
微信小程序 列表刷新:
微信小程序,最近自己學(xué)習(xí)微信小程序的知識(shí),就想實(shí)現(xiàn)現(xiàn)在APP 那種列表刷新,下拉刷新,上拉加載等功能。
先開看一下界面


1.wx.request (獲取遠(yuǎn)程服務(wù)器的數(shù)據(jù),可以理解成$.ajax)
2. scroll-view的兩個(gè)事件
2.1 bindscrolltolower(滑到頁面底部時(shí))
2.2 bindscroll (頁面滑動(dòng)時(shí))
2.3 bindscrolltoupper (滑倒頁面頂部時(shí))
然后我們看代碼,詳細(xì)描述。
index.js
var url = "http://www.imooc.com/course/ajaxlist";
var page =0;
var page_size = 20;
var sort = "last";
var is_easy = 0;
var lange_id = 0;
var pos_id = 0;
var unlearn = 0;
// 獲取數(shù)據(jù)的方法,具體怎么獲取列表數(shù)據(jù)大家自行發(fā)揮
var GetList = function(that){
that.setData({
hidden:false
});
wx.request({
url:url,
data:{
page : page,
page_size : page_size,
sort : sort,
is_easy : is_easy,
lange_id : lange_id,
pos_id : pos_id,
unlearn : unlearn
},
success:function(res){
//console.info(that.data.list);
var list = that.data.list;
for(var i = 0; i < res.data.list.length; i++){
list.push(res.data.list[i]);
}
that.setData({
list : list
});
page ++;
that.setData({
hidden:true
});
}
});
}
Page({
data:{
hidden:true,
list:[],
scrollTop : 0,
scrollHeight:0
},
onLoad:function(){
// 這里要非常注意,微信的scroll-view必須要設(shè)置高度才能監(jiān)聽滾動(dòng)事件,所以,需要在頁面的onLoad事件中給scroll-view的高度賦值
var that = this;
wx.getSystemInfo({
success:function(res){
console.info(res.windowHeight);
that.setData({
scrollHeight:res.windowHeight
});
}
});
},
onShow:function(){
// 在頁面展示之后先獲取一次數(shù)據(jù)
var that = this;
GetList(that);
},
bindDownLoad:function(){
// 該方法綁定了頁面滑動(dòng)到底部的事件
var that = this;
GetList(that);
},
scroll:function(event){
// 該方法綁定了頁面滾動(dòng)時(shí)的事件,我這里記錄了當(dāng)前的position.y的值,為了請(qǐng)求數(shù)據(jù)之后把頁面定位到這里來。
this.setData({
scrollTop : event.detail.scrollTop
});
},
refresh:function(event){
// 該方法綁定了頁面滑動(dòng)到頂部的事件,然后做上拉刷新
page = 0;
this.setData({
list : [],
scrollTop : 0
});
GetList(this)
}
})
index.wxml
<view class="container">
<scroll-view scroll-top="{{scrollTop}}" scroll-y="true" style="height:{{scrollHeight}}px;"
class="list" bindscrolltolower="bindDownLoad" bindscroll="scroll" bindscrolltoupper="refresh">
<view class="item" wx:for="{{list}}">
<image class="img" src="{{item.pic_url}}"></image>
<view class="text">
<text class="title">{{item.name}}</text>
<text class="description">{{item.short_description}}</text>
</view>
</view>
</scroll-view>
<view class="body-view">
<loading hidden="{{hidden}}" bindchange="loadingChange">
加載中...
</loading>
</view>
</view>
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- 微信小程序 下拉列表的實(shí)現(xiàn)實(shí)例代碼
- 微信小程序?qū)崿F(xiàn)給循環(huán)列表添加點(diǎn)擊樣式實(shí)例
- 微信小程序開發(fā)之好友列表字母列表跳轉(zhuǎn)對(duì)應(yīng)位置
- 微信小程序?qū)崿F(xiàn)城市列表選擇
- 微信小程序 教程之列表渲染
- 微信小程序 實(shí)現(xiàn)列表項(xiàng)滑動(dòng)顯示刪除按鈕的功能
- 微信小程序項(xiàng)目總結(jié)之點(diǎn)贊 刪除列表 分享功能
- 微信小程序本地緩存數(shù)據(jù)增刪改查實(shí)例詳解
- 微信小程序?qū)崿F(xiàn)多選刪除列表數(shù)據(jù)功能示例
相關(guān)文章
Android判斷App前臺(tái)運(yùn)行還是后臺(tái)運(yùn)行(運(yùn)行狀態(tài))
這篇文章主要介紹了Android判斷App前臺(tái)運(yùn)行還是后臺(tái)運(yùn)行的相關(guān)資料,需要的朋友可以參考下2016-04-04
Android table布局開發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android table布局開發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05
Android Studio preview 不固定及常見問題的解決辦法
preview 可以幫助您預(yù)覽您的布局文件將如何在用戶的設(shè)備上呈現(xiàn)。這篇文章主要介紹了Android Studio preview 不固定及常見問題的解決辦法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
Android Button按鈕點(diǎn)擊背景和文字變化操作
這篇文章主要介紹了Android Button按鈕點(diǎn)擊背景和文字變化操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08
Andriod Studio實(shí)現(xiàn)保存QQ密碼功能(案例代碼詳解)
這篇文章主要介紹了Andriod Studio實(shí)現(xiàn)保存QQ密碼功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
android之BroadcastReceiver應(yīng)用詳解
這篇文章主要介紹了android之BroadcastReceiver應(yīng)用詳解,BroadcastReceiver也就是“廣播接收者”的意思,顧名思義,它就是用來接收來自系統(tǒng)和應(yīng)用中的廣播。有興趣的可以了解一下。2016-12-12
Android實(shí)現(xiàn)一周時(shí)間早中晚排班表
項(xiàng)目需求需要實(shí)現(xiàn)一個(gè)動(dòng)態(tài)添加,修改一周早中晚時(shí)間排班表,文章給大家提供了實(shí)現(xiàn)代碼,需要的朋友參考下吧2018-07-07
Android Fragment 和 FragmentManager 的代碼分析
這篇文章主要介紹了Android Fragment 和 FragmentManager 的代碼分析,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-01-01
Android Studio debug.keystore位置介紹
這篇文章主要介紹了Android Studio debug.keystore位置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
詳解Android(共享元素)轉(zhuǎn)場(chǎng)動(dòng)畫開發(fā)實(shí)踐
本篇文章主要介紹了詳解Android(共享元素)轉(zhuǎn)場(chǎng)動(dòng)畫開發(fā)實(shí)踐,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-08-08

