List of articles

### Opening remarks :
Cloud development as the name implies
It's back-end development , It should be the open ability launched by wechat only last week , Now it reminds me of the past leancloud, And earlier bmob了, and leancloud We started to support the development of wechat small programs , Comparatively speaking ,leancloud We should have more information , But after all, wechat's own products , It's still necessary to try .
Here is a summary of the experience , First of all, wechat's API It has the flavor of wechat , Here is the initialization method .

wx.cloud.init({ // Environmental Science ID env: 'much-de492f', // Get call api People's information traceUser: true, })
So it's very convenient . Secondly, when adding data, it is completely graphical , That's good .


### You can see it clearly

* aggregate = surface
* record = data elements
of course Only one database can be created , It was empty the first time I came in , Just name it when you build it .
### Remember to put IED Upgrade to the latest version This is the cloud development .


### Secondly, change the call base library to the latest one


### If you have your watch set up Then the rest is called
requestData: function() { wx.showLoading({ title: ' Loading ', }) var that = this;
//resourceItem Is the table name wx.cloud.database().collection('resourceItem').get({ success:
function(res) { that.setData({ //res yes json //res.data It's data //res.errMsg Tips
titleDatas: res.data }) console.log(JSON.stringify(res)) wx.hideLoading() } })
},
### If it appears [] Empty array :
Generally, it is the database part above Of Permission settings not modified


### Back end cloud paging

However, there is an irritating problem in the end cloud , All the logic needs to be processed on the front end , Especially paging , No matter what lendCloud Or is there no support for wechat development , Then you need to write it yourself when you create the database ID, Use the
where Filtering , Although it is a solution , however ·· I find ID It's a random number !
But it doesn't matter , In index management, we see it in ascending order , A false alarm , So we just need to put the last one ID Compare to achieve paging .

### Here is the solution
load fun
requesListData: function(type) { var that = this // Gets a list of the corresponding types wx.showLoading({
title: ' Loading ', }) console.log("type = " + type) var db = wx.cloud.database()
const _ = db.command db.collection(type).limit(2).where({ _id:
_.gt(this.data.lastId) }).get({ success: function(res) { wx.hideLoading() if
(res.data.length == 0) { if (that.data.pageNum == 1) { that.data.listData = []
} that.data.hasMore = false } else { that.data.hasMore = true for (var i = 0; i
< res.data.length; i++) { var data = res.data[i] that.data.listData.push(data)
if (i + 1 == res.data.length) { that.data.lastId = data._id } } }
that.setData({ listData: that.data.listData, selectedtype: type, pageNum:
that.data.pageNum + 1, lastId: that.data.lastId, hasMore: that.data.hasMore })
}, fail: function(res) { // The database was not found console.log("===fail===" + res)
wx.hideLoading() }, }) }, /** * Handle function of bottom pull event on page */ onReachBottom: function() {
if (!this.data.hasMore) return; var type = this.data.selectedtype
this.requesListData(type) }, /** * Initial data of the page */ data: { hasMore: true, lastId:
'0', selectedtype: 'book', selectedTagId: '', pageNum: 1, },
Core code :gt() Function to find the ID Big elements ( Default return 20 strip , here limit There are two restrictions )
db.collection(type).limit(2).where({ _id: _.gt(this.data.lastId) })
okay , There are so many simple introductory tutorials for wechat cloud development .

### reference material :

* Slog71_ Cloud development of wechat applet - Whole stack Era 3
<https://blog.csdn.net/u010997452/article/details/82676378>
* Applets · Cloud development
<https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html>
Pay attention to the official account for more dry cargo