WeChatアプレットのロードがもっと多い(すなわちリストの改ページ)
3880 ワード
app.json中:
"window": {
"enablePullDownRefresh": true //
}
wxmlにおいて:
{{item.title}}
{{item.inputtime}}
{{item.content}}
js中:data: {
hidden: true, //
page: 1, //
pageSize: 10, //
hasMoreData: true, // ,
contentlist: [], // ,
},
//
getInfo: function (message) {
var that = this;
wx.showNavigationBarLoading() //
wx.showLoading({ // loading
title: message,
})
wx.request({
url: 'http://localhost:88/wechat/test.php', //
data: { page: that.data.page, count: that.data.pageSize },
method: 'post',
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: function (res) {
var contentlistTem = that.data.contentlist;
if (res.data.length > 0) {
wx.hideNavigationBarLoading() //
wx.hideLoading() // loading
if (that.data.page == 1) {
contentlistTem = []
}
var contentlist = res.data;
if (contentlist.length < that.data.pageSize) {
that.setData({
contentlist: contentlistTem.concat(contentlist),
hasMoreData: false
})
} else {
that.setData({
contentlist: contentlistTem.concat(contentlist),
hasMoreData: true,
page: that.data.page + 1
})
}
}
},
fail: function (res) {
wx.hideNavigationBarLoading()
wx.hideLoading()
fail()
},
complete: function (res) {
},
})
},
/**
* --
*/
onLoad: function (options) {
// options
var that = this
that.getInfo(' ...')
},
/**
* --
*/
onPullDownRefresh: function () {
this.data.page = 1
this.getInfo(' ')
},
/**
*
*/
onReachBottom: function () {
if (this.data.hasMoreData) {
this.getInfo(' ')
} else {
wx.showToast({
title: ' ',
})
}
},
バックグラウンドphpで: $chang){
return mb_substr($str, 0, $chang, 'utf-8').'...';
}else{
return $str;
}
}
// , ,
$conn = mysql_connect("127.0.0.1", "username", "password")or die("Mysql Connect Error");
//
mysql_select_db("hiretianxia");
// ,
mysql_query("SET NAMES UTF8");
// ,
ini_set("date.timezone", "PRC");
// ,
$page = $_POST['page'];
$count = $_POST['count'];
$ind = ($page - 1) * $count;
$sql = "select * from article order by id desc limit ".$ind.', '.$count;
$result = mysql_query($sql, $conn);
if (mysql_num_rows($result) > 0) {//
$data = array();
while($row = mysql_fetch_array($result)){
// "" , '',
$zifu = '{"id":"'.$row['id'].'","title":"'.cut_str($row['title'], 8).'","content":"'.cut_str(str_replace(' ', '', strip_tags(htmlspecialchars_decode($row['content']))), 24).'","inputtime":"'.$row['inputtime'].'"}';
// json , true
$data[] = json_decode($zifu);
}
// json , json
echo json_encode($data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}
mysql_close($conn);
?>
以下のコードはphp 5.4以上でサポートされます.JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT