原創(chuàng)聲明:本文為作者原創(chuàng),未經(jīng)允許不得轉(zhuǎn)載,經(jīng)授權(quán)轉(zhuǎn)載需注明作者和出處
@小木 @Michael 我這里有一個項(xiàng)目需求:我的下拉刷新的效果怎么這么另類呢
直接上代碼
wxml:
<view class="container" style="padding:0rpx">
<scroll-view scroll-top="{{scrollTop}}" scroll-y="true" style="height:{{scrollHeight}}px;"
class="list" bindscrolltolower="bindDownLoad" bindscrolltoupper="topLoad" bindscroll="scroll">
<!--內(nèi)容-->
<view class="item" wx:for="{{list}}" wx:key="listid">
<view class="text">
<text class="username">{{item.order_goodstitle}}</text>
<text class="phone">{{item.order_sjmoney}}</text>
</view>
</view>
<view class="loading" hidden="{{searchLoading}}">正在載入更多...</view>
<view class="loading complete" hidden="{{searchLoadingComplete}}">已加載全部</view>
</scroll-view>
<view class="body-view">
<loading hidden="{{hidden}}" bindchange="loadingChange">
加載中...
</loading>
</view>
</view>
js:
var page = 0;
var loadMore = function(that){
that.setData({
hidden: false
});
//發(fā)送請求
wx.request({
url: 'http://localhost:80/work/bbs/index.php/Home/Show/showlist',
data:{
pageindex:page,
},
header: {
'content-type': 'application/json'
},
success:function(res){
console.log(res.data);
var list = res.data;
if (res.data != ''){
that.setData({
searchLoading: false,
list: list,
searchLoading:true
});
}else{
that.setData({
searchLoadingComplete:false,
searchLoading: true
})
}
page++;
that.setData({
hidden: true
});
}
})
}
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
//searchPageNum: 1, // 設(shè)置加載的第幾次,默認(rèn)是第一次
searchLoading: true, //"上拉加載"的變量,
searchLoadingComplete: true , //“沒有數(shù)據(jù)”的變量
hidden: true,
list: [], //放置返回數(shù)據(jù)的數(shù)組
scrollTop: 0,
scrollHeight: 0,
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function () {
//這里要注意,微信的scroll-view必須要設(shè)置高度才能監(jiān)聽滾動事件,所以,需要在頁面的onLoad事件中給scroll-view的高度賦值
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
scrollHeight: res.windowHeight
});
}
});
loadMore(that);
},
//滑動到底部的時候
bindDownLoad:function(res){
var that = this;
loadMore(that);
},
scroll: function (event) {
// 該方法綁定了頁面滾動時的事件,我這里記錄了當(dāng)前的position.y的值,為了請求數(shù)據(jù)之后把頁面定位到這里來。
this.setData({
scrollTop: event.detail.scrollTop
});
},
后端php(TP3.2):
```php
namespace HomeController;
use ThinkController;
class ShowController extends Controller{
public function showlist(){
//傳遞過來的頁數(shù)
$pageindex = $_GET[‘pageindex’];
$page_size = 10;
$obj = M(‘goodstj_mon_copy’);
$count = $obj->count();
$Page = new ThinkPage($count, $page_size);
$list = $obj->limit($pageindex,$page_size)->select();
//dump($Page);die;
if($list){
$this->ajaxReturn($list,’JSON’);
}else{
echo “失敗”;
}
}
}
時間比較急,希望大神幫忙看下.